Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need to match all user properties from top assembly to lower assemblys and all parts in unit. this must include all types of user properties (num, text, multi text, true/false.) this is so I can drive parts and add properties to large assemblys
this is what i have so far
' iLogic Rule to Copy/Create User Parameters in Parts and Assemblies Sub Main() ' Define the assembly document as the active document Dim asmDoc As AssemblyDocument asmDoc = ThisApplication.ActiveDocument ' Iterate through all components in the assembly For Each comp As ComponentOccurrence In asmDoc.ComponentDefinition.Occurrences ' Get the document for the component Dim compDoc As Document compDoc = comp.Definition.Document Dim mainParams As UserParameters mainParams = asmDoc.ComponentDefinition.Parameters.UserParameters ' Loop through all user parameters in the main assembly For Each mainParam As UserParameter In mainParams ' Check if the parameter already exists in the component If Not ParameterExists(compDoc, mainParam.Name) Then ' Create the parameter in the component if it doesn't exist CreateUserParameter(compDoc, mainParam.Name, mainParam.Value, mainParam.Units) End If ' Copy the parameter value from the main assembly to the component CopyParameterValue(asmDoc, compDoc, mainParam.Name) Next Next End Sub Function ParameterExists(doc As Document, paramName As String) As Boolean ' Check if a parameter with the given name exists in the document Try Dim param As Parameter param = doc.ComponentDefinition.Parameters.UserParameters.Item(paramName) Return True Catch ex As Exception Return False End Try End Function Sub CreateUserParameter(doc As Document, paramName As String, paramValue As Object, paramUnits As UnitsTypeEnum) ' Create a new user parameter in the document Try Dim param As UserParameter param = doc.ComponentDefinition.Parameters.UserParameters.AddByValue(paramName, paramValue, paramUnits) Catch ex As Exception ' Handle any errors that may occur when creating the parameter End Try End Sub Sub CopyParameterValue(sourceDoc As Document, targetDoc As Document, paramName As String) ' Copy the parameter value from the source document to the target document Try Dim sourceParam As Parameter sourceParam = sourceDoc.ComponentDefinition.Parameters.UserParameters.Item(paramName) Dim targetParam As Parameter targetParam = targetDoc.ComponentDefinition.Parameters.UserParameters.Item(paramName) If sourceParam.Value.GetType() Is GetType(String) Then targetParam.Expression = sourceParam.Expression ElseIf sourceParam.Value.GetType() Is GetType(Boolean) Then targetParam.Expression = IIf (CBool(sourceParam.Value), "True", "False") Else targetParam.Value = sourceParam.Value End If Catch ex As Exception ' Handle any errors that may occur when copying the parameter value End Try End Sub
and this is the error I'm fighting with
Conversion from string "Text" to type 'Integer' is not valid.
Solved! Go to Solution.