000

iLogic: Working with the Active Sketch

.

Issue:
You're working with sketches in some iLogic code and want to be able to find the active sketch name, or active sketch number. 



Solution:
Here are a couple of quick rules that will do this. And also as a bonus there is a quick rule to delete all sketches in the part.

Rule1: Find the active sketch name



Dim oSketch As PlanarSketch
If Typeof ThisApplication.ActiveEditObject Is Sketch Then
oSketch = ThisApplication.ActiveEditObject
MessageBox.Show(oSketch.Name & " is the active Sketch", "iLogic")
Else
MessageBox.Show("Active Edit Object is not a Sketch", "iLogic")
End If




Rule2: Find the active sketch number



Dim oSketches As PlanarSketches
oSketches = ThisApplication.ActiveDocument.ComponentDefinition.Sketches

i=1
For Each oSketch in oSketches
            oSketch = oSketches.Item(i)
                   If oSketch Is ThisApplication.ActiveEditObject Then
                   MessageBox.Show("The active sketch is number: " & i, "iLogic")
                   Else
                   End If
          i=i+1  
Next
 



Rule3: Delete all sketches.



Dim oSketches As PlanarSketches
oSketches = ThisApplication.ActiveDocument.ComponentDefinition.Sketches

If Typeof ThisApplication.ActiveEditObject Is Sketch Then
ThisApplication.ActiveEditObject.ExitEdit
Else
End If

For Each oSketch in oSketches
            oSketch = oSketches.Item(oSketch.Name)
          oSketch.Delete
Next
 

Blog Archive