user parameters from ipt to iam

user parameters from ipt to iam

A.K.CORTEL
Enthusiast Enthusiast
155 Views
1 Reply
Message 1 of 2

user parameters from ipt to iam

A.K.CORTEL
Enthusiast
Enthusiast

Hi all , I need to pass all user parameters and reference parameter's from part top assembly this must include all types of user properties (num, text, multi text, true/false.) so I can drive parts and add properties to large assembly's.
Can someone provide a code?

0 Likes
156 Views
1 Reply
Reply (1)
Message 2 of 2

Curtis_Waguespack
Consultant
Consultant

@A.K.CORTEL , you can export/import the parameters via the XML to do this manually, and then your assembly will have these parameters ready in the assembly, so that you can push the parameter values to the parts via code.

 

If that won't work for your needs, you could use this to copy the parameters of all parts to the the assembly? 

 

' Get the active assembly document
Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition

' Get user parameters collection of the assembly
Dim oAsmParams As UserParameters = oDef.Parameters.UserParameters

' Track number of parameters added and skipped
Dim paramsAdded As Integer = 0
Dim paramsSkipped As Integer = 0

' Process each referenced document
For Each refDoc As Document In oDoc.AllReferencedDocuments
    Try
        ' Get user parameters from referenced document
        Dim refParams As UserParameters = refDoc.ComponentDefinition.Parameters.UserParameters
        
        ' Process each parameter in referenced doc
        For Each refParam As UserParameter In refParams
            Try
                ' Check if parameter already exists
                Dim existingParam As UserParameter = Nothing
                Try
                    existingParam = oAsmParams.Item(refParam.Name)
                Catch
                    ' Parameter doesn't exist - add it
                    oAsmParams.AddByValue(refParam.Name, refParam.Value, refParam.Units)
                    paramsAdded += 1
                    Logger.Info($"Added parameter {refParam.Name} from {refDoc.DisplayName}")
                    Continue For
                End Try
                
                ' Parameter exists - skip it
                paramsSkipped += 1
                Logger.Info($"Skipped existing parameter {refParam.Name}")
                
            Catch ex As Exception
                Logger.Error($"Failed to process parameter {refParam.Name}: {ex.Message}")
            End Try
        Next
        
    Catch ex As Exception
        Logger.Error($"Error processing document {refDoc.DisplayName}: {ex.Message}")
    End Try
Next

' Show summary
MessageBox.Show($"Parameters added: {paramsAdded}" & vbCrLf & $"Parameters skipped: {paramsSkipped}", "Parameter Copy Complete")

 

EESignature

0 Likes