Get Section View Data Example (VB.NET)
This example shows how to get the data for a section view in a part.
'-------------------------------------------------------------------------
' Preconditions:
' 1. Open install_dir\samples\tutorial\cosmosxpress\aw_rubber_duct.sldprt.
' 2. Create a section view with three sections:
' a. Right-click Front in the FeatureManager design tree
' and click Section View.
' b. Set X Rotation to 45.00deg in Section 1.
' c. Select Section 2, click Top, and
' set X Rotation to 45.00deg.
' d. Select Section 3, click Right, and
' set X Rotation to 45.00deg.
' e. Click Save twice.
' 3. Click View > Display > Section View twice.
' 4. Open the Immediate window.
'
' Postconditions:
' 1. Gets and prints data about each section in
' the section view to the Immediate window.
' 2. Examine the Immediate window.
'
' NOTE: Because the part is used elsewhere, do not save changes.
'------------------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
Partial Class SolidWorksMacro
Public Sub main()
Dim swModel As ModelDoc2
Dim swModelViewMgr As ModelViewManager
Dim swSectionViewData As SectionViewData
Dim swSelMgr As SelectionMgr
Dim status As Boolean
swModel = swApp.ActiveDoc
swSelMgr = swModel.SelectionManager
'Get section view
swModelViewMgr = swModel.ModelViewManager
swSectionViewData = swModelViewMgr.GetSectionViewData("")
DisplayDebugInformation(swSectionViewData, swSelMgr)
swModel.ClearSelection2(True)
End Sub
'Select the planes and print each section's data
Sub DisplayDebugInformation(ByVal data As SectionViewData, ByVal selMgr As SelectionMgr)
Dim p1 As Feature
Dim p2 As Feature
Dim p3 As Feature
Dim swMathTransform As MathTransform
Dim transform As Object
p1 = data.FirstPlane
If Not p1 Is Nothing Then p1.Select2(True, 1)
p2 = data.SecondPlane
If Not p2 Is Nothing Then p2.Select2(True, 2)
p3 = data.ThirdPlane
If Not p3 Is Nothing Then p3.Select2(True, 4)
Debug.Print("----------Section 1----------")
Debug.Print("Offset: " & data.FirstOffset)
Debug.Print("Rotation X: " & data.FirstRotationX)
Debug.Print("Rotation Y: " & data.FirstRotationY)
Debug.Print("Color: " & data.FirstColor)
Debug.Print("Reverse direction: " & data.FirstReverseDirection)
Debug.Print("----------Section 2----------")
Debug.Print("Offset: " & data.SecondOffset)
Debug.Print("Rotation X: " & data.SecondRotationX)
Debug.Print("Rotation Y: " & data.SecondRotationY)
Debug.Print("Color: " & data.SecondColor)
Debug.Print("Reverse direction: " & data.SecondReverseDirection)
Debug.Print("----------Section 3----------")
Debug.Print("Offset: " & data.ThirdOffset)
Debug.Print("Rotation X: " & data.ThirdRotationX)
Debug.Print("Rotation Y: " & data.ThirdRotationY)
Debug.Print("Color: " & data.ThirdColor)
Debug.Print("Reverse direction: " & data.ThirdReverseDirection)
swMathTransform = data.GetDynamicCenterTransform(3)
Debug.Print("Dynamic center transform:")
transform = swMathTransform.ArrayData()
If Not IsNothing(transform) Then
Debug.Print(" Rotate: " & Format(transform(0), "###0.0#####") & " " & Format(transform(1), "###0.0#####") & " " & Format(transform(2), "###0.0#####"))
Debug.Print(" " & Format(transform(3), "###0.0#####") & " " & Format(transform(4), "###0.0#####") & " " & Format(transform(5), "###0.0#####"))
Debug.Print(" " & Format(transform(6), "###0.0#####") & " " & Format(transform(7), "###0.0#####") & " " & Format(transform(8), "###0.0#####"))
Debug.Print(" Translate: " & Format(transform(9), "###0.0#####") & " " & Format(transform(10), "###0.0#####") & " " & Format(transform(11), "###0.0#####"))
End If
Debug.Print("----------Section Cap---------")
Debug.Print("Show section cap: " & data.ShowSectionCap)
End Sub
''' <summary>
''' The SldWorks swApp variable is pre-assigned for you.
''' </summary>
Public swApp As SldWorks
End Class