Hi @ForrestJudd. I do not believe they have updated or created a new version of that Parameter() iLogic shortcut snippet, which allows you to specify a ModelState name yet. They do have a couple other new iLogic shortcut snippets for other purposes which will work with a specific ModelState though. So, if a situation calls for it, we basically need to create our own similar functioning methods (a custom Sub routine). That simple iLogic snippet can work in some situations, but when the ModelState that the assembly component object is set to doesn't match the ModelState that is currently 'active' in the model file being referenced by that component, it may not work right. An example case may be where your assembly has several component instances, which all reference the same source model document, but each of those components may be set to different ModelState versions of it. Basically each ModelState represents a different version of the document, and you need to be working with what is called the 'factory' document, which is essentially just the version of the document that is currently under the influence of the 'active' ModelState. That is the only version you can make edits/changes to. You can sometimes access/read data from other versions, but can't make changes to them.
Here is one such custom function I made a while back that may be able to help you with this seemingly simple task. It is fairly long though, in an attempt to get it free of potential errors/problems. It is not set up exactly like the iLogic snippet, but it worked OK in my scenario testing. Plus, other versions can be made, that work slightly different, if needed. You can review its contents to follow what is going on. I left some comments in there to help understand the train of thought, and why I am doing some of the things I am doing.
Sub Main
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
'get the source parameter / value to copy down
Dim oTopAsmParam As Inventor.Parameter = Nothing
Try
oTopAsmParam = oADoc.ComponentDefinition.Parameters.Item("Param2Copy")
Catch
MsgBox("Failed to find/get 'source' parameter/value.", vbCritical, "")
Exit Sub
End Try
'find/get component representing part within the sub-assembly
Dim oTargetPartOcc As ComponentOccurrence = Nothing
Try
oTargetPartOcc = oADoc.ComponentDefinition.Occurrences.ItemByName("Part3:2")
Catch
MsgBox("Failed to find/get component representing the Part within the Sub-Assembly.", vbCritical, "")
Exit Sub
End Try
CopyParamToComponentWithModelState(oTargetPartOcc, oTopAsmParam)
End Sub
Sub CopyParamToComponentWithModelState(oOcc As ComponentOccurrence, oSourceParam As Inventor.Parameter, _
Optional oTargetModelStateName As String = vbNullString, Optional oTargetParamName As String = vbNullString)
If IsNothing(oOcc) OrElse IsNothing(oSourceParam) Then Exit Sub
If oOcc.Suppressed Then Exit Sub 'or try to open its referened document to be able to access its param
If oTargetModelStateName = "" Then oTargetModelStateName = oOcc.ActiveModelState
If oTargetParamName = "" Then oTargetParamName = oSourceParam.Name
If TypeOf oOcc.Definition Is VirtualComponentDefinition Then Exit Sub
'get the 'factory' document, if one exists (the version we can edit)
Dim oFacDoc As Document
If oOcc.Definition.IsModelStateMember Then
oFacDoc = oOcc.Definition.FactoryDocument
Else
oFacDoc = oOcc.Definition.Document
End If
Dim oMSs As ModelStates = oFacDoc.ComponentDefinition.ModelStates
'make sure the specified ModelState exists. If so, get it.
Dim oTargetMS As ModelState = Nothing
Try
oTargetMS = oMSs.Item(oTargetModelStateName)
Catch
'could offer to create the ModelState if it is not found too
Logger.Error("Failed to find ModelState named '" & oTargetModelStateName & _
"' within component named '" & oOcc.Name & "'.")
Exit Sub
End Try
'record whether we opened the factory document, so we know if we need to close it again when done
Dim oFacDocOpened As Boolean = False
'that ModelState must either be 'active' or get 'activated' before you can edit a param within it
If oMSs.ActiveModelState IsNot oTargetMS Then
'if the target ModelState is not 'active', or the MemberEditScope is not set to 'edit active member',
'then the factory document will need to be 'visibly' opened before you can 'activate' that ModelState,
'and before you can change the MemberEditScope status, both of which will need to happen
oFacDoc = ThisApplication.Documents.Open(oFacDoc.FullDocumentName, True)
oFacDocOpened = True
oTargetMS.Activate
End If
If oMSs.MemberEditScope <> MemberEditScopeEnum.kEditActiveMember Then
oMSs.MemberEditScope = MemberEditScopeEnum.kEditActiveMember
End If
Dim oParams As Inventor.Parameters = oFacDoc.ComponentDefinition.Parameters
'make sure target parameter exists. If not, try to create it.
Dim oTargetParam As Inventor.Parameter = Nothing
Try
oTargetParam = oParams.Item(oTargetParamName)
Catch
oTargetParam = oParams.UserParameters.AddByValue(oTargetParamName, oSourceParam.Value, oSourceParam.Units)
Catch
Logger.Error("Failed to find or create target parameter named '" & oTargetParamName & _
"' within component named '" & oOcc.Name & "'.")
Exit Sub
End Try
If Not IsNothing(oTargetParam) Then
If oTargetParam.Value <> oSourceParam.Value Then
oTargetParam.Value = oSourceParam.Value
End If
End If
If oFacDoc.RequiresUpdate Then oFacDoc.Update2(True)
If oFacDoc.Dirty Then oFacDoc.Save2(False)
If oFacDocOpened Then oFacDoc.Close(True)
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)