Help: Get iProperties selection Item by API

Help: Get iProperties selection Item by API

ngdnam88
Advocate Advocate
748 Views
10 Replies
Message 1 of 11

Help: Get iProperties selection Item by API

ngdnam88
Advocate
Advocate

Dears,

Could you please help me check what's wrong in my Code that I'm using to read selection item's iProperties:

Dim AssemblyDOC As AssemblyDocument = _InventorApp.ActiveDocument
Dim ITEM = _InventorApp.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select an Item")
If (Not ITEM Is Nothing) Then
	Dim ITEMPropertySets As PropertySets = ITEM.PropertySets
	Dim ITEMPropertySet As PropertySet = nITEMPropertySets.Item("Design Tracking Properties")
	Dim ITEMPartNumber As Property = nITEMPropertySet.Item("Part Number")
	MsgBox("THE PART NUMBER: " & ITEMPartNumber)
End If

I'm using VS2022 + Inventor 2018

Thank you very much!

0 Likes
749 Views
10 Replies
Replies (10)
Message 2 of 11

WCrihfield
Mentor
Mentor
Accepted solution

Hi @ngdnam88.  The object you are most likely returning from your Pick method is a ComponentOccurrence, not a Document object.  The ComponentOccurrence object does not directly have a 'PropertySets' property, that is only accessible from a Document type object.  There are a few ways to access the iProperties that are associated with an assembly component, but none of them are direct, the way you have it there.  If going the API way, similar to what you have above, then you will need to get the Document that the assembly component represents first, then you can use that Document to access the iProperties from.  There are two ways to get the Document from a component:

 - ComponentOccurrence.ReferencedDocumentDescriptor.ReferencedDocument

 - ComponentOccurrence.Definition.Document

Or, if the component is a 'top level' one (not within a sub assembly), you may be able to use the iLogic shortcut snippet iProperties.Value(ComponentOccurrence.Name, "PropertySetName", "Property.Name") to access it.

Edit:  Below is an example of one way to alter your code.

Dim AssemblyDOC As AssemblyDocument = _InventorApp.ActiveDocument
Dim ITEM = _InventorApp.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select an Item")
If (Not ITEM Is Nothing) Then
	Dim oComp As ComponentOccurrence = ITEM 'or try to Cast it to correct Type
	Dim oCompDoc As Document = oComp.ReferencedDocumentDescriptor.ReferencedDocument
	Dim ITEMPropertySets As PropertySets = oCompDoc.PropertySets
	Dim ITEMPropertySet As PropertySet = ITEMPropertySets.Item("Design Tracking Properties")
	Dim ITEMPartNumber As Inventor.Property = ITEMPropertySet.Item("Part Number")
	MsgBox("THE PART NUMBER: " & ITEMPartNumber)
End If

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 11

bradeneuropeArthur
Mentor
Mentor
Accepted solution
Dim AssemblyDOC As AssemblyDocument = ThisApplication.ActiveDocument
Dim ITEM As Inventor.ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select an Item")

If (Not ITEM Is Nothing) Then
	Dim ITEMPropertySets As PropertySets = ITEM.Definition.Document.PropertySets
	Dim ITEMPropertySet As PropertySet = ITEMPropertySets.Item("Design Tracking Properties")
	Dim ITEMPartNumber As Inventor.Property = ITEMPropertySet.Item("Part Number")
	MsgBox("THE PART NUMBER: " & ITEMPartNumber.Value)
End If

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 4 of 11

ngdnam88
Advocate
Advocate
Thanks for your explain @WCrihfield,
It's very useful for me who starting to learn with code.
0 Likes
Message 5 of 11

ngdnam88
Advocate
Advocate

Dear @WCrihfield , @bradeneuropeArthur 

By this way can we get the physical properties (Mass, Volume, ...) selected item? Could you help me how to do it?

Thank you very much!

0 Likes
Message 6 of 11

bradeneuropeArthur
Mentor
Mentor
Accepted solution

 

Dim AssemblyDOC As AssemblyDocument = ThisApplication.ActiveDocument
Dim ITEM As Inventor.ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select an Item")

If (Not ITEM Is Nothing) Then
	Dim a As Inventor.Document = ITEM.Definition.Document

	
	MsgBox("THE MASS IS: " & a.ComponentDefinition.MassProperties.Mass)
End If

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 7 of 11

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Or more options like this:

 

Dim AssemblyDOC As AssemblyDocument = ThisApplication.ActiveDocument
Dim ITEM As Inventor.ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select an Item")

If (Not ITEM Is Nothing) Then
	Dim a As Inventor.Document = ITEM.Definition.Document
	
	Dim MyMass As String= a.ComponentDefinition.MassProperties.Mass
	Dim MyVolume As String = a.ComponentDefinition.MassProperties.Volume
	Dim MyArea As String = a.ComponentDefinition.MassProperties.Area
	
	MsgBox("THE MASS: " & MyMass)
	MsgBox("THE VOLUME: " & MyVolume)
	MsgBox("THE AREA: " & MyArea)
End If

Best regards,

 

Arthur Knoors

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 8 of 11

ngdnam88
Advocate
Advocate

Thank you very much! @bradeneuropeArthur 

I learnt to much from your codes. I'm trying get Material of selected item. Could you please help me?

0 Likes
Message 9 of 11

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Hi,

 

Use this:

Dim AssemblyDOC As AssemblyDocument = ThisApplication.ActiveDocument
Dim ITEM As Inventor.ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select an Item")

If (Not ITEM Is Nothing) Then
	Dim ITEMPropertySets As PropertySets = ITEM.Definition.Document.PropertySets
	Dim ITEMPropertySet As PropertySet = ITEMPropertySets.Item("Design Tracking Properties")
	Dim ITEMMaterial As Inventor.Property = ITEMPropertySet.Item("Material")
	MsgBox("THE PART NUMBER: " & ITEMMaterial.Value)
End If

 

Regards,

 

Arthur Knoors

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 10 of 11

ngdnam88
Advocate
Advocate

Thanks for your help @WCrihfield @bradeneuropeArthur 
I got it, and I can understand the key for my question is: 

Dim ITEM As Inventor.Document = ITEM.Definition.Document

ngnam1988_0-1671624654924.png

 

0 Likes
Message 11 of 11

bradeneuropeArthur
Mentor
Mentor

Please read this overview of properties:

Regards,

 

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature