Create Derived or Underived Sketch Example VB
Create Derived or Underived Sketch Example (VBA)
This example shows how to create a derived or underived sketch.
'-------------------------------------------
' Preconditions:
' (1)
Part document is open that
' contains
at least one sketch.
' (2)
Select an underived sketch, run the macro, and
' examine
both the FeatureMananger design
' tree
and the Immediate Window for results.
' (3)
Run the macro again, but this time select
' the
just created derived sketch
' and
examine both the FeatureManager design
' tree
and the Immediate Window for results.
'
'
' Postconditions:
' (1)
If the sketch is not derived, then a
' derived
sketch is created.
' (2)
If the selected sketch is derived,
' then
it is underived.
'---------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swSketch As SldWorks.Sketch
Sub main()
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
'
Interactively select a sketch
Set
swSelMgr = swModel.SelectionManager
Set
swFeat = swSelMgr.GetSelectedObject6(1,
-1)
Set
swSketch = swFeat.GetSpecificFeature2
'
Is the selected sketch derived?
Debug.Print
("Is the selected sketch derived? " & swSketch.IsDerived)
'
If the selected sketch is a derived sketch,
'
then create a derived sketch; else underive the
'
selected sketch
If
swSketch.IsDerived Then
swModel.UnderiveSketch
Debug.Print
(" Selected
sketch was derived; sketch is now underived.")
Else
swModel.DeriveSketch
Debug.Print
(" Selected
sketch was not derived; a derived sketch has been created.")
End
If
swModel.ForceRebuild3 (False)
End Sub