Create Derived or Underived Sketch Example (VB.NET)
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.
'---------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconstImports S
Imports System.Diagnostics
 
Partial Class SolidWorksMacro
 
    Public 
 Sub main()
 
        Dim 
 swModel As ModelDoc2
        Dim 
 swSelMgr As SelectionMgr
        Dim 
 swFeat As Feature
        Dim 
 swSketch As Sketch
 
        swModel 
 = swApp.ActiveDoc
 
        ' 
 Interactively select a sketch 
        swSelMgr 
 = swModel.SelectionManager
        swFeat 
 = swSelMgr.GetSelectedObject6(1, 
 -1)
        swSketch 
 = swFeat.GetSpecificFeature2
 
        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
 
    ''' 
 <summary>
    ''' 
 The SldWorks swApp variable is pre-assigned for you.
    ''' 
 </summary>
    Public 
 swApp As SldWorks
 
End Class