Create Section View at Specified Location Example (VBA)
This example shows how to create a section view at a specified location.
'-------------------------------------------------------------------
'
' Preconditions: Drawing document with at least one view
is open.
'
' Postconditions: Section view created at specified location.
'
'--------------------------------------------------------------------
Dim swApp As SldWorks.SldWorks
Dim swDrawing As SldWorks.DrawingDoc
Dim vChildComponents As Variant
Dim swFirstDrawingView As SldWorks.View
Dim swDrawingView As SldWorks.View
Dim swDrRootComponent As SldWorks.DrawingComponent
Sub main()
Set
swApp = Application.SldWorks
Set
swDrawing = swApp.ActiveDoc
If
swDrawing Is Nothing Then
MsgBox
"There is no active document"
Exit
Sub
End
If
'
Always return the drawing sheet
Set
swFirstDrawingView = swDrawing.GetFirstView
'
Get next drawing sheet
Set
swDrawingView = swFirstDrawingView.GetNextView
'
Get root
drawing component
Set
swDrRootComponent = swDrawingView.RootDrawingComponent
If
swDrRootComponent.GetChildrenCount
> 0 Then
vChildComponents
= swDrRootComponent.GetChildren
For
iChild = 0 To UBound(vChildComponents)
Next
iChild
End
If
'
Select the drawing view and create line for the section view
boolstatus
= swDrawing.Extension.SelectByID2("Drawing
View1", "DRAWINGVIEW", 0.1776750819672, 0.1542113114754,
0, False, 0, Nothing, swSelectOptionDefault)
swDrawing.ClearSelection2 True
swDrawing.CreateLine2 -0.1627297255825, 0.003478881358533,
0, 0.1883732252372, 0.003478881358533, 0
'
Set arguments for call to create section view
Dim
x As Double, y As Double, z As Double
Dim
notAligned As Boolean, isOffsetSection As Boolean, chgdirection As Boolean,
scwithmodel As Boolean, partial As Boolean, dispsurfcut As Boolean
Dim
label As String
Dim
sectionView As SldWorks.View
x
= 0.2222307644306
y
= 0.08908737704918
z
= 0
notAligned
= False
isOffsetSection
= False
chgdirection
= False
scwithmodel
= False
partial
= False
dispsurfcut
= False
label
= "A"
'
Create section view
Set
sectionView = swDrawing.CreateSectionViewAt3(x,
y, z, notAligned, isOffsetSection, label, chgdirection, scwithmodel, partial,
dispsurfcut, (vChildComponents))
End Sub