Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Identifying features with Hidden sketches

7 REPLIES 7
Reply
Message 1 of 8
CadUser46
432 Views, 7 Replies

Identifying features with Hidden sketches

Im working on a macro that throws up a messagebox to alert the user there is unconstrained sketches in their model.  I have ran into a problem that i genuinely never noticed before.

Certain features create a sketch that is hidden from view in the browser and is only visible in the API.  eg Move Face, Flange.

 

1. What is the best way to identify the complete list of features that exhibit this behavior?

2. My macro, currently, just iterates through each sketch and throws the msgbox if its kUnderConstrainedConstraintStatus' but what is the best way to check which parent feature is consuming each sketch? 

 

The two features i have listed above will always result in the sketch being underconstrained so i want to check the parent feature before throwing the msgbox.

 

Craig


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
7 REPLIES 7
Message 2 of 8

Hi Craig,

 

Unfortunately I don't have the complete list of features that exhibit this behavior. You would need to try them all and find out by yourself I'm afraid.

 

You can use the PlanarSketch.Dependents property to iterate through the list of objects depending on that sketch, you will find there the features consuming the sketch.

 

I hope it helps,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 3 of 8

Philippe.  Can you help me export a list of all the features in the component definition object, im struggling with object types.

 

I can see what i want in the watch window but my efforts to print the list out to something i can manipulate in Excel are in vain.

 

I was heading in this direction.

 

Private Sub PrintFeatureNames()

    Dim oDoc As Inventor.PartDocument: Set oDoc = ThisApplication.ActiveDocument

    Dim oFeatures As Features: Set oFeatures = oDoc.ComponentDefinition.Features     Dim oFeature As Object         Print #1, Tab(10); "Feature Name"         For Each oFeature In oFeatures         Print #1, oFeature.Type         Open "C:\temp\FeatureNames.txt" For Output As #1         Next     Close #1 End Sub


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
Message 4 of 8

the type is an integer value, because it's an enum, so most likely you will need to write a small utility function that will convert the enum into a readable string, or you end up with the integer value in your excel file and implement some logic when you read that file based on the integer value... I'm not sure what you want to with the xls afterwards.

 

Here is a snipet that works fine on my side:

 

Function TypeToStr(t As ObjectTypeEnum) As String

    TypeToStr = "Unsupported type..."

   Select Case t
        Case ObjectTypeEnum.kExtrudeFeatureObject
            TypeToStr = "Extrude Feature"
        Case ObjectTypeEnum.kRevolveFeatureObject
            TypeToStr = "Revolve Feature"
        ' And so on ...
    End Select
    
End Function


Sub PrintFeatures()

    Dim doc As PartDocument
    Set doc = ThisApplication.ActiveDocument
    
    Open "C:\temp\features.txt" For Output As #1
    
    Dim feature As PartFeature
    For Each feature In doc.ComponentDefinition.features
    
        Print #1, "Feature: " & feature.name & " Type: " & TypeToStr(feature.Type)
    
    Next
    
    Close #1
    
End Sub

 Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 5 of 8

Basically i was looking to build that kind of case statement by not having to go through each object type.  ie Get the list easily, manipulate the list in excel then paste back into a vba case statement.

 

I guess you're saying this is not possible and the only way is to manually (visually) read the enums and create each case statement one by one....sad face.

 

Moving on from that small problem is there somewhere that explains the meaning of the contraint status flag?  In the attached file the hidden sketch in flange 1 shows kUnderConstrainedConstraintStatus yet the fully contrained sketches under Hole1 to 4 show kUnknownContrainstStatus.  The one sketch (sketch3) that is genuinely under constrained (8 dims needed according to status bar) also shows as kUnknownContrainstStatus.

 

I am baffled as to how im supposed to identify sketch3 reliably and not see false positives like sketch2. Surely kUnderConstrainedConstraintStatus should be tied to the status bar notification of requiring dims?

 

 

 

 


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
Message 6 of 8
CadUser46
in reply to: CadUser46

How do i address the dependant objects?  I must admit i dont understand what enumerated objects mean, are & how to use them.

 

    Dim oSketch As Sketch
    Dim oFeatureType As Object
   
    For Each oSketch In oDoc.ComponentDefinition.Sketches
        For Each oFeatureType In oDoc.ComponentDefinition.Sketches(oSketch).Dependents


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
Message 7 of 8

It's an ObjectsEnumerator, which means it can contains objects of different types:

 

dim obj as Variant

For Each obj in Dependents

 

 'Then either do a Select/case of the obj.Type

  Select Case obj.type
             Case kExtrudeFeatureObject

             dim extr as ExtrudeFeature

             set extr = obj

 

'Or a simple type check

 If (TypeOf obj Is ExtrudeFeature) Then

    dim extr as ExtrudeFeature
     set extr = obj



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 8 of 8

I have made some progress based on the sugestions you made but hit a new roadblock. I have a test model with many features and unconsumed sketches. I believe the error is being generated by the unconsumed sketches because the Dependants enum is not a collection until the sketch is consumed by a feature.

 

How do i address an emtpy enum as per the attached picture? I have already tried:

If oDoc.ComponentDefinition.Sketches(oSketch.Name).Dependents Is Nothing Then

If oDoc.ComponentDefinition.Sketches(oSketch.Name).Dependents.Count > 0 then

If oDoc.ComponentDefinition.Sketches(oSketch.Name).Dependents = Nothing Then

If oDoc.ComponentDefinition.Sketches(oSketch.Name).Dependents Is Null Then

 

Is it possible to handle this correctly without using error handling to ignore the error?

 

Also for completness i have added a table showing most of the feature types and there behavior.


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report