Automating Instance iProperty Creation inside of Inventor Drawing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The end goal is to be able to add/change an instance iProperty of a single component when selected within a drawing view. The current method is to open the assembly in another window, orient the part and verify that the component is the same one in the drawing, then right click instance properties, create a new property.
The property I want to create is "VIEW QTY". Right now, the balloons in the drawing show the total qty of the BOM, and I want to only call out a portion of the BOM, because the view (or assembly step) only needs a portion of the total. So in one view, I want to call out 10 nuts, and in another view, 5 nuts, but the total is 15. Creating an instance property, I can reference "VIEW QTY" in the balloon, and change it to whatever number I like. Ideally, the number would correlate to the BOM total qty, but that is beyond my scope for now.
Below is the code that Google Gemini helped me create, so when you look at the code and ask "Why did he do that?!", it's because I didn't do it. I'm not smart enough to write my own code, yet.
I know the first error is Line 3: Component is undefined. I don't know where to look to find all the objects I can use. I know it's not a valid object because the text is Orange, not Purple. Not sure how to fix this.
Sub Main() ' Prompt the user to pick a component Dim pickedComponent As Component = ThisApplication.ActiveDocument.ComponentDefinition.PickComponent("Select a component:", False) ' Check if a component was picked If Not pickedComponent Is Nothing Then ' Prompt the user for the "VIEW QTY" value Dim viewQty As String = InputBox("Enter the VIEW QTY value:", "VIEW QTY") ' Set the "VIEW QTY" iProperty instance value of the selected component pickedComponent.iProperties.SetInstanceProperty("VIEW QTY", viewQty) ' Inform the user that the property has been set MsgBox("VIEW QTY property set to: " & viewQty) Else ' If no component was picked, inform the user MsgBox("No component was selected.") End If End Sub
Any and all help is appreciated. Thanks!