Determine which feature was created by using a specific sketch, API

Determine which feature was created by using a specific sketch, API

Anonymous
Not applicable
1,156 Views
6 Replies
Message 1 of 7

Determine which feature was created by using a specific sketch, API

Anonymous
Not applicable

This is API related and might be better in this part of the forum, so i'll post the link to thread here

 

https://forums.autodesk.com/t5/inventor-forum/determine-which-feature-was-created-by-using-a-specifi...

 

Hi!

I want to determine which extrusion feature was created used a specific sketch by using the API.

Other wording: Link between sketch and extrion by using the API?

 

iterated over all sketches and then found the sketch that matches my criteria. I am trying to export all features like holes and extrusions. Holes can also be designed as extrusions, so I identified all skeches which use circular sketches. In order to find out more about the "hole", I need to analyse the extrusion feature. I didn't find anything capable of finding the feature which made use of this specific sketch.

 

Thanks!

 

0 Likes
1,157 Views
6 Replies
Replies (6)
Message 2 of 7

clutsa
Collaborator
Collaborator

If I understand, you have a sketch that's a shared sketch. You want to know what features are referencing that sketch (just like "Relationships..." but threw the API)?

 

Dim app As Application= ThisApplication
Dim doc As Document = app.ActiveDocument
Dim compDef As ComponentDefinition = doc.ComponentDefinition
'your code to find your sketch goes here...
Dim mySketch As Sketch = compDef.sketches("Sketch1") 'your code will be diffrent
For Each dependent In mySketch.Dependents
	If dependent.Type = objectTypeEnum.kExtrudeFeatureObject Then
		MessageBox.Show("Sketch used in: " & dependent.Definition.Parent.Name, "Title")
	End If
Next
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

Message 3 of 7

Anonymous
Not applicable
Yes that's it, expect that the sketch isn't shared.
0 Likes
Message 4 of 7

clutsa
Collaborator
Collaborator

Did you have anymore questions? If the code from my last post answered your question please accept as solution. 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 5 of 7

BrianEkins
Mentor
Mentor

A sketch doesn't know which features use it.  Typically, a sketch is used by a single feature, but it's possible that any number of features can be based on the same sketch.

 

However, a feature does know which sketch it's based on.  Most features are based on profiles, which is a subset of geometry within a sketch that use selects when creating the feature.  The various feature objects provide access to the Profile that they use and from the profile, you can get its parent sketch.  Below is a simple VBA program that looks for extrude features that are based on a specific sketch.  Hopefully, this helps.

 

Public Sub GetFeatureFromSketch()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    Dim partComp As PartComponentDefinition
    Set partComp = partDoc.ComponentDefinition
    
    ' Get the sketch of interest.
    Dim sk As sketch
    Set sk = partComp.Sketches.Item("Sketch3")
    
    ' Iterate through the Extrude features to see if any of them use this sketch.
    Dim extrude As ExtrudeFeature
    For Each extrude In partComp.Features.ExtrudeFeatures
        ' Get the profile used for the extrusion.
        Dim prof As Profile
        Set prof = extrude.Definition.Profile
        
        ' Get the parent sketch of the profile.
        Dim extrudeSketch As sketch
        Set extrudeSketch = prof.Parent
        
        ' Check if the two sketches are the same.
        If extrudeSketch Is sk Then
            MsgBox "Extrusion " & extrude.name & " uses " & sk.name
        End If
    Next
End Sub
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 6 of 7

clutsa
Collaborator
Collaborator

That's what I was trying to do at first as well but I couldn't get back to the sketch. I had looked at profile and it's items but missed that it's parent was the sketch. 

I do have to disagree that a sketch doesn't know what features use it. If you check the first code I posted, you can track it down under the dependents.definition.parent (I did find that parent =p)

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 7 of 7

BrianEkins
Mentor
Mentor

You're right, I forgot about the Dependents property.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes