- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'd appreciate any help with the following.
I've gone through many earlier posts, and I can't get the code to change the Model State and Parameter of an assembly occurrence to work.
I've gotten it to work in iLogic, but I need to move to VB.Net for various reasons to make an Add-in.
I prompt the user for input, which gives me the information for the needed model state and the value of the parameter that needs to change. I also need to set the occurrence to Global Edit. Below is the snippet for iLogic.
Dim AssDoc As AssemblyDocument = ThisApplication.ActiveDocument 'Set Grille style using Model States Dim Occ As Inventor.ComponentOccurrence = AssDoc.ComponentDefinition.Occurrences.ItemByName("Linear Bar") Dim partdoc As PartDocument = Occ.Definition.FactoryDocument Dim MSGSS As New ModelStatesGlobalScope(partdoc) Occ.ActiveModelState=BarGrilleStyle InventorVb.DocumentUpdate() partdoc.ComponentDefinition.Parameters.ModelParameters.Item("Length").Value = LinearBarLength*2.54 'convert from cm to in
Here's the VB code
Dim oDoc As AssemblyDocument
oDoc = g_inventorApplication.ActiveDocument
Dim oAssemblyCompDef As AssemblyComponentDefinition
oAssemblyCompDef = oDoc.ComponentDefinition
' Specify an occurrence to change its active model state.
Dim oOccu As ComponentOccurrence
oOccu = oAssemblyCompDef.Occurrences(1)
' Get native document ComponentDefinition of occurrence.
Dim oOccuDef As ComponentDefinition
oOccuDef = oOccu.Definition
oOccu.ActiveModelState = "CA400"
I referenced code from the following:
https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-045E78DB-DBE3-4220-8EBC-29EB53890E1A
Here's the message I get.
Solved! Go to Solution.
Link copied