Hello together,
this code works for parts. But how to change it that it works for assemblys? I would like to select a part and than change the value.
m_invApp = GetObject(, "Inventor.Application")
' Get the Parameters object. Assumes a part or assembly document is active.
Dim oParameters As Parameters
oParameters = m_invApp.ActiveDocument.ComponentDefinition.Parameters
' Get the parameter named "Length".
Dim oLengthParam As Parameter
oLengthParam = oParameters.Item("Diam")
' Change the equation of the parameter.
oLengthParam.Expression = TxtBox10.Text
' Update the document.
m_invApp.ActiveDocument.Update()
Thanks
Georg
Hi Georg,
ActiveDocument.ComponentDefinition means the ComponentDefinition of the assembly if the active document is an assembly. So the code will access the params of assembly, instead of the part. So for your case, the code could looks like below. Please pay attention to the code in color.
m_invApp = GetObject(, "Inventor.Application")
' Get the Parameters object. Assumes a part or assembly document is active.
' assume one part is selected.
Dim oOcc As ComponentOccurrence
oOcc = m_invApp.ActiveDocument.SelectSet(1)
' get the part ComponentDefinition
Dim oPartDef As PartComponentDefinition
Set oPartDef = oOcc.Definition
' get the params of the part
Dim oParameters As Parameters
' oParameters = m_invApp.ActiveDocument.ComponentDefinition.Parameters
oParameters = oPartDef .Parameters
' Get the parameter named "Length".
Dim oLengthParam As Parameter
oLengthParam = oParameters.Item("Diam")
' Change the equation of the parameter.
oLengthParam.Expression = TxtBox10.Text
' Update the document.
m_invApp.ActiveDocument.Update()
if you find the occurrence is not selected, you can use Document.SelectSet.Select to select it again.
I tried to select the part but it does not work. Please could you post an example.
It is very straightforward. just input the entity you want to select in the method
Document.SelectSet.Select.
I am starting to be curious how you did. Could you share your code?