Hi, try with this rule. I have also added the functions to send each parameter to the document iproperties, if you do not need it you can remove it. This is a possible way to perform the task from the assembly.
Dim oAssyDoc As AssemblyDocument = ThisDoc.Document
Dim oAssyDef As AssemblyComponentDefinition = oAssyDoc.ComponentDefinition
Dim ParamName As String
For Each oOcc As ComponentOccurrence In oAssyDef.Occurrences
Dim rDoc As Document = oOcc.definition.document
If rDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
'Add and check Parameters
ParamName = "WIDTH"
ParamValue = 9.6 ' Value in cm
Try
rDoc.ComponentDefinition.Parameters.UserParameters.item(ParamName).value = ParamValue
Catch
rDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(ParamName, ParamValue , "mm")
oParam = rDoc.ComponentDefinition.Parameters.UserParameters.Item(ParamName)'get the parameter
oParam.ExposedAsProperty = True'export the paramter as an iProperty
oParam.CustomPropertyFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType'kNumberPropertyType
oParam.CustomPropertyFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision'kThreeDecimalPlacesPrecision
oParam.CustomPropertyFormat.ShowUnitsString=False
oParam.CustomPropertyFormat.ShowTrailingZeros = False
oParam.CustomPropertyFormat.ShowLeadingZeros = False
End Try
ParamName = "HEIGHT"
ParamValue = 7.5 ' Value in cm
Try
rDoc.ComponentDefinition.Parameters.UserParameters.item(ParamName).value = ParamValue
Catch
rDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(ParamName, ParamValue , "mm")
oParam = rDoc.ComponentDefinition.Parameters.UserParameters.Item(ParamName)'get the parameter
oParam.ExposedAsProperty = True'export the paramter as an iProperty
oParam.CustomPropertyFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType'kNumberPropertyType
oParam.CustomPropertyFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision'kThreeDecimalPlacesPrecision
oParam.CustomPropertyFormat.ShowUnitsString=False
oParam.CustomPropertyFormat.ShowTrailingZeros = False
oParam.CustomPropertyFormat.ShowLeadingZeros = False
End Try
ParamName = "THK"
ParamValue = 0.317 ' Value in cm
Try
rDoc.ComponentDefinition.Parameters.UserParameters.item(ParamName).value =ParamValue
Catch
rDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(ParamName, ParamValue , "mm")
oParam = rDoc.ComponentDefinition.Parameters.UserParameters.Item(ParamName)'get the parameter
oParam.ExposedAsProperty = True'export the paramter as an iProperty
oParam.CustomPropertyFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType'kNumberPropertyType
oParam.CustomPropertyFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision'kThreeDecimalPlacesPrecision
oParam.CustomPropertyFormat.ShowUnitsString=False
oParam.CustomPropertyFormat.ShowTrailingZeros = False
oParam.CustomPropertyFormat.ShowLeadingZeros = False
End Try
End if
Next
Parameter.UpdateAfterChange = True
iLogicVb.UpdateWhenDone = True
Below you have the code without sending these parameters to document properties
Dim oAssyDoc As AssemblyDocument = ThisDoc.Document
Dim oAssyDef As AssemblyComponentDefinition = oAssyDoc.ComponentDefinition
Dim ParamName As String
For Each oOcc As ComponentOccurrence In oAssyDef.Occurrences
Dim rDoc As Document = oOcc.definition.document
If rDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
'Add and check Parameters
ParamName = "WIDTH"
ParamValue = 9.6 ' Value in cm
Try
rDoc.ComponentDefinition.Parameters.UserParameters.item(ParamName).value = ParamValue
Catch
rDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(ParamName, ParamValue , "mm")
End Try
ParamName = "HEIGHT"
ParamValue = 7.5 ' Value in cm
Try
rDoc.ComponentDefinition.Parameters.UserParameters.item(ParamName).value = ParamValue
Catch
rDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(ParamName, ParamValue , "mm")
End Try
ParamName = "THK"
ParamValue = 0.317 ' Value in cm
Try
rDoc.ComponentDefinition.Parameters.UserParameters.item(ParamName).value =ParamValue
Catch
rDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(ParamName, ParamValue , "mm")
End Try
End If
Next
Parameter.UpdateAfterChange = True
iLogicVb.UpdateWhenDone = True
I hope the codes can serve you for your task. regards
Please accept as solution and give likes if applicable.
I am attaching my Upwork profile for specific queries.
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn