You can try this:
Sub Main()
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub
Dim doc As AssemblyDocument = ThisDoc.FactoryDocument
Dim paramsData As New List(Of List(Of Object))
paramsData.Add(New List(Of Object) From {"extent_dim_X", "1", UnitsTypeEnum.kMillimeterLengthUnits})
paramsData.Add(New List(Of Object) From {"extent_dim_Y", "1", UnitsTypeEnum.kMillimeterLengthUnits})
paramsData.Add(New List(Of Object) From {"extent_dim_T", "1", UnitsTypeEnum.kMillimeterLengthUnits})
paramsData.Add(New List(Of Object) From {"part_area", "1", UnitsTypeEnum.kMillimeterLengthUnits})
paramsData.Add(New List(Of Object) From {"bend_number", "1", UnitsTypeEnum.kUnitlessUnits})
paramsData.Add(New List(Of Object) From {"Xcubic", "1", UnitsTypeEnum.kMillimeterLengthUnits})
paramsData.Add(New List(Of Object) From {"Ycubic", "1", UnitsTypeEnum.kMillimeterLengthUnits})
paramsData.Add(New List(Of Object) From {"Zcubic", "1", UnitsTypeEnum.kMillimeterLengthUnits})
paramsData.Add(New List(Of Object) From {"thread_hole_number", "1", UnitsTypeEnum.kUnitlessUnits})
EnsureParamsExist(doc, paramsData)
Dim allSubAsms As List(Of Document) = doc.AllReferencedDocuments.Cast(Of Inventor.Document).Where(Function(d) d.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject).ToList
If allSubAsms Is Nothing OrElse allSubAsms.Count = 0 Then Exit Sub
For Each oSubAsm In allSubAsms
EnsureParamsExist(oSubAsm, paramsData)
Next
Dim allSubParts As List(Of Document) = doc.AllReferencedDocuments.Cast(Of Inventor.Document).Where(Function(d) d.DocumentType = DocumentTypeEnum.kPartDocumentObject).ToList
If allSubParts Is Nothing OrElse allSubAsms.Count = 0 Then Exit Sub
For Each part In allSubParts
Try
CopyUserParameters(doc, part)
Catch ex As Exception
MsgBox("Problems while making parameter copies to part: " & part.DisplayName)
End Try
Next
If doc.RequiresUpdate Then doc.Update2(True)
End Sub
Public Sub CopyUserParameters(sourceDoc As AssemblyDocument, targetDoc As PartDocument)
Dim sourceParameters As UserParameters = sourceDoc.ComponentDefinition.Parameters.UserParameters
Dim targetParameters As UserParameters = targetDoc.ComponentDefinition.Parameters.UserParameters
Dim targetParametersList As List(Of UserParameter) = targetDoc.ComponentDefinition.Parameters.UserParameters.Cast(Of UserParameter).ToList()
For Each source As UserParameter In sourceParameters
If (targetParametersList.Contains(source)) Then
Dim newParameter = targetParameters.Item(source.Name)
newParameter.Expression = source.Expression
newParameter.ExposedAsProperty = True
Else
Dim newParameter = targetParameters.AddByExpression(source.Name, source.Expression, source.Units)
newParameter.ExposedAsProperty = True
' iLogicVb.UpdateWhenDone = True
End If
Next
End Sub
Sub EnsureParamsExist(oDoc As Document, oParamsData As List(Of List(Of Object)))
If oDoc Is Nothing Or (oParamsData Is Nothing OrElse oParamsData.Count = 0) Then Exit Sub
If oDoc.IsModifiable = False Then Exit Sub
Dim oUParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters
For Each MainEntry In oParamsData
If MainEntry.Count = 0 Then Continue For
Dim oUParam As UserParameter = Nothing
Try
oUParam = oUParams.Item(MainEntry.First)
Catch
oUParam = oUParams.AddByExpression(MainEntry.First, MainEntry.Item(1), MainEntry.Last)
End Try
Try
If Not oUParam.ExposedAsProperty Then oUParam.ExposedAsProperty = True
Dim oCPF As CustomPropertyFormat = oUParam.CustomPropertyFormat
oCPF.Units = oDoc.UnitsOfMeasure.GetStringFromType(MainEntry.Last)
oCPF.Precision = CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
oCPF.ShowLeadingZeros = True
oCPF.ShowTrailingZeros = True
Catch
End Try
Next
End Sub
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog: hjalte.nl - github.com