Get name of feature, based on the used sketch - Ilogic

Get name of feature, based on the used sketch - Ilogic

jaco011
Advocate Advocate
1,154 Views
2 Replies
Message 1 of 3

Get name of feature, based on the used sketch - Ilogic

jaco011
Advocate
Advocate

Hi all,

I am currently working on a Ilogic rule to find easily undefined sketches, to check a part. I have already the code as shown below. Which makes undefined sketches visible and shows the names of those sketches in a message box. But to find these sketches you still have to search trough your features. Anybody know how to get the name of the feature where a sketch is used in?

My goal is that the messagebox say "1 undefined sketch. Sketch 3 used in extrude 5"

Anyone with suggestions?

Thanks a lot

 

 

 

Dim oDoc As PartDocument
oDoc = ThisDoc.Document

Dim counter As Integer = 0
Dim oSketch As PlanarSketch

Dim ListSketch As New ArrayList
Dim oText As String 


For Each oSketch In oDoc.ComponentDefinition.Sketches
	If oSketch.ConstraintStatus <> 51713  Then
		oSketch.Visible = True
		counter += 1
		Dim oSketchName As String = oSketch.Name
		ListSketch.Add(oSketch.Name)
	Else
		oSketch.Visible = False
	End If
Next

For i As Integer = 0 To ListSketch.Count - 1
	If i = 0 Then 
		oText = ListSketch(i)
	Else
		oText = oText & vbLf & ListSketch(i)
	End If
Next

If counter = 0 Then
	MessageBox.Show("Good job, no undefined sketches!", "No undefined sketches",MessageBoxButtons.OK)
Else
	MessageBox.Show("There are " & counter & " undefined sketches." & vbLf & vbLf & "The following sketches are undefined" & vbLf & oText, counter &"Undefined sketches",MessageBoxButtons.OK)
End If

 

0 Likes
Accepted solutions (1)
1,155 Views
2 Replies
Replies (2)
Message 2 of 3

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @jaco011 

Since a sketch can have multiple features depending on it, we'll have to find them all...

This is a small example that finds the part features depending on a sketch 🙂

 

Dim oSketch As PlanarSketch = ThisDoc.Document.ComponentDefinition.Sketches(1) 'Get a sketch
Dim oNames As String = "Features:"
For Each oObj In oSketch.Dependents
	If TypeOf (oObj) Is PartFeature Then oNames = oNames & vbCrLf & DirectCast(oObj, PartFeature).Name
Next
MsgBox(oNames)
Message 3 of 3

jaco011
Advocate
Advocate

Thanks that worked!

My final code will be;

 

Dim oDoc As PartDocument

oDoc = ThisDoc.Document

 

Dim counter As Integer = 0

Dim oSketch As PlanarSketch

 

Dim ListSketch As New ArrayList

Dim ListFeature As New ArrayList

Dim oText As String

Dim oNames As String

 

For Each oSketch In oDoc.ComponentDefinition.Sketches

               oSketch.Visible = False

Next

 

For Each oSketch In oDoc.ComponentDefinition.Sketches

        If oSketch.ConstraintStatus <> 51713  Then

               oSketch.Visible = True

               counter += 1

               Dim oSketchName As String = oSketch.Name

               ListSketch.Add(oSketch.Name)

              

               oNames = ""

              

               For Each oObj In oSketch.Dependents

                       If TypeOf (oObj) Is PartFeature Then

                               oNames = oNames & vbCrLf & "   > " & DirectCast(oObj, PartFeature).Name

                       End if

                       Next

               ListFeature.Add (oNames)

        End If

Next

 

For i As Integer = 0 To ListSketch.Count - 1

        If i = 0 Then

               oText = ListSketch(i) & " used in " & ListFeature(i) & vbLf

        Else

               oText = oText & vbLf & ListSketch(i) & " used in " & ListFeature(i)

        End If

Next

 

If counter = 0 Then

        MessageBox.Show("Good job! No undefined sketches in this part", "No undefined sketches",MessageBoxButtons.OK)

Else

        MessageBox.Show("There are " & counter & " undefined sketches" & vbLf & vbLf & "It is about the following sketches" & vbLf & vbLf & oText, counter &" undefined sketches",MessageBoxButtons.OK)

End If

 

 

0 Likes