- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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 IfI'm using VS2022 + Inventor 2018
Thank you very much!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @ngnam1988. 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
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It's very useful for me who starting to learn with code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Please read this overview of properties:
Regards,
Regards,
Arthur Knoors
Autodesk Affiliations:
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: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 !