Pushing Parameters to all parts

Ever wanted to drive an entire assembly from the top level but are struggling with skeleton frames or linked Excel sheets? This is probably your answer. 

Below is a great example of how simply copy and pasting some iLogic code can save you hours of time.

It is important to set up your parts to have all the important parameters you want to use, but once that is it done, it is a simple case of changing your parameters at the top level and 'pushing' them to the parts and sub assemblies below. 

Check the video and try it out!


The code you need is after the break: 



 

Public Sub Main()

CopyUserParams()

End Sub


Private Sub CopyUserParams()

    If ThisDoc.Document.DocumentType <> Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then

        MsgBox("The active document must be an assembly.")

        Return

    End If


    Dim asmDoc As Inventor.AssemblyDocument = ThisDoc.Document

    For Each refDoc As Inventor.Document In asmDoc.AllReferencedDocuments

        ' Look for part documents.

        If refDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then

            Dim partDoc As Inventor.PartDocument = refDoc

            Dim refDocUserParams As UserParameters = partDoc.ComponentDefinition.Parameters.UserParameters


            ' Add the assembly parameters to the part.

            For Each asmUserParam As UserParameter In asmDoc.ComponentDefinition.Parameters.UserParameters

                ' Check to see if the parameter already exists.

                Dim checkParam As UserParameter = Nothing

                Try

                    checkParam = refDocUserParams.Item(asmUserParam.Name)

                Catch ex As Exception

                    checkParam = Nothing

                End Try


                If checkParam Is Nothing Then

                    ' Create the missing parameter.

                    refDocUserParams.AddByExpression(asmUserParam.NameasmUserParam.ExpressionasmUserParam.Units)

                Else

                    ' Update the value of the existing parameter.

                    checkParam.Expression = asmUserParam.Expression

                End If

            Next

        End If

    Next

iLogicVb.UpdateWhenDone = True


End Sub

Comments

Popular posts from this blog

Style Library Conflicts

Auto Unfold