Access Assembly Features through iLogic

Access Assembly Features through iLogic

Anonymous
Not applicable
637 Views
3 Replies
Message 1 of 4

Access Assembly Features through iLogic

Anonymous
Not applicable

Hi All,

 

I'm now having an issue accessing the features in an assembly, the error message is attached and the following is the relative code.

 

The error line is between the 2 Test Messages:

 

------------------------------------------------------------------------------------

 

'Create a Component Definition relative to the Part Document

Dim oFeature As Features


Dim oAssembly As AssemblyDocument
oAssembly = oCompOcc.Definition.Document


MsgBox("Test 1")


'Cycle through all features in the Part
For Each oFeature In oAssembly.ComponentDefinition.Features


MsgBox("Test 2")

 

----------------------------------------------------------------------

 

Thanks in Advance

Mitch

 

 

0 Likes
638 Views
3 Replies
Replies (3)
Message 2 of 4

MegaJerk
Collaborator
Collaborator

Stolen from the VBA Inventor Api help file, subject - Features : 


  • Represents the collection of features in the assembly context. The API does not yet support addition of assembly features.

After reading that I realized that it was just a matter of calling it differently 

 

 

' Get the active document.
Dim doc As AssemblyDocument
doc = ThisApplication.ActiveDocument

Dim oCompDef As ComponentDefinition
oCompDef = doc.ComponentDefinition

Dim oFeature As Features
oFeature = oCompDef.Features

MsgBox("Test 1")

'Cycle through all features in the Part
For Each Item In oFeature

MsgBox(Item.Type)

Next

 

So as you can see, 'Features' is just the total collection of all of the feature objects from your assembly. 

I hope that this helps to clear things up. 

 

 

 

 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
0 Likes
Message 3 of 4

Anonymous
Not applicable

Hi Megajerk,

 

I apologize I guess there was more information I left out. I'm cycling through all Assemblies and Parts in an even bigger Assembly. So these features were in a Sub Assembly which is why I used the component occurences.

 

I was able to solve it by using the PartFeatures Object in this location as well:

 

-------------------------------------------------------------------------------------------

 

Dim oPartFeature As PartFeature

 

'Create a Component Definition relative to the Assembly Document
Dim oAssembly As AssemblyDocument
oAssembly = oCompOcc.Definition.Document


'Cycle through all features in the Assembly
For Each oPartFeature In oAssembly.ComponentDefinition.Features

 

---------------------------------------------------------------------------------------------

 

This seemed to do it, I believe Inventor uses the Features under the "Model" tab in an Assembly as Part Features(Even though you're technically in an Assembly). Which makes some sense as you're modelling the assembly just as if it were a part when using those features.

 

Thanks for the input though!

Mitch

0 Likes
Message 4 of 4

MegaJerk
Collaborator
Collaborator

I thought that there was more than was being revealed 😉 ! It's alright though because I learned some things from it. To be honest, I had no idea that there even were Assembly level features that you could use, and though I later found that they don't really change my life at all (work life or otherwise), it's still nice to know that they exist. 

I also became frustrated when I found that the object type of the features was of type ObjectTypeEnum, which doesn't seem to be listed in the htm help files of the Inventor Api. That led me on a magical ride of misfortune and discoveries. Eventually I found a way to dump all of those enum values / names to a text file, but there's more work to be done! 

Glad  you figured it all out. 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
0 Likes