Hide Table of Contents

Create Section View in Model Example (C#)

This example shows how to create a section view in a model.

//---------------------------------------------------------------------------
// Preconditions:
// 1. Open:
//    install_dir\samples\tutorial\multibody\multi_bridge.sldprt.
// 2. Right-click the project in Project Explorer and select:
//    Add Reference > .NET > Microsoft.VisualBasic.
// 3. Rename the namespace to match the name of your C# project.
//
// Postconditions: The graphics area displays the section view with
// three sections that are capped in color.

// NOTE: Because the model is used elsewhere,
// do not save changes when closing it.
//---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
using Microsoft.VisualBasic;

namespace CreateSectionView_CSharp.csproj
{
    
partial class SolidWorksMacro
    {

        
ModelDoc2 swModel;
        
ModelDocExtension swModelDocExt;
        
ModelViewManager swModelViewMgr;
        
SelectionMgr swSelMgr;
        
SectionViewData svData;
        
Feature plane1;
        
Feature plane2;
        
Feature plane3;

        
bool boolstatus;

        
public void Main()
        {
            swModel = (
ModelDoc2)swApp.ActiveDoc;
            swModelDocExt = swModel.Extension;
            swModelViewMgr = swModel.ModelViewManager;

            swSelMgr = (
SelectionMgr)swModel.SelectionManager;

            boolstatus = swModelDocExt.SelectByID2(
"Front", "PLANE", -0.04751707843116, 0.04466659468449, 0.1209999999999, false, 1, null, 0);
            boolstatus = swModelDocExt.SelectByID2(
"Top", "PLANE", -0.06781533387408, 0.00100317525596, 0.1263684575364, true, 2, null, 1);
            boolstatus = swModelDocExt.SelectByID2(
"Right", "PLANE", -0.000808330303073, 0.07304457560201, -0.003890984556108, true, 4, null, 1);

            svData = swModelViewMgr.CreateSectionViewData();
            FillPlaneData(svData, swSelMgr);

            boolstatus = swModelViewMgr.CreateSectionView(svData);
            
Debug.Print(" Section bodies are valid: " + boolstatus);

        }

        
public void FillPlaneData(SectionViewData data, SelectionMgr selMgr)
        {
            plane1 = (
Feature)selMgr.GetSelectedObject6(1, 0);
            plane2 = (
Feature)selMgr.GetSelectedObject6(2, 0);
            plane3 = (
Feature)selMgr.GetSelectedObject6(4, 0);

            data.FirstPlane = plane1;
            data.FirstReverseDirection =
false;
            data.FirstOffset = -0.01;
            data.FirstRotationX = 0.296705972839036;
            data.FirstRotationY = 0.174532925199433;
            data.FirstColor =
Information.RGB(255, 0, 0);

            data.SecondPlane = plane2;
            data.SecondReverseDirection =
false;
            data.SecondOffset = 0.01;
            data.SecondRotationX = 0.296705972839036;
            data.SecondRotationY = 0.174532925199433;
            data.SecondColor =
Information.RGB(0, 255, 0);

            data.ThirdPlane = plane3;
            data.ThirdReverseDirection =
true;
            data.ThirdOffset = -0.01;
            data.ThirdRotationX = 0.296705972839036;
            data.ThirdRotationY = 0.174532925199433;
            data.ThirdColor =
Information.RGB(0, 0, 255);

            data.Redraw =
true;
            data.ShowSectionCap =
true;
            data.KeepCapColor =
true;

        }

        
public SldWorks swApp;

    }
}



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Create Section View in Model Example (C#)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2013 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.