Populating my parameters using iLogic

tecnico3S7Z5
Explorer

Populating my parameters using iLogic

tecnico3S7Z5
Explorer
Explorer

Currently I'm using a code of iLogic I found to populate my parameters from the parent assembly to it's child components

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.Name, asmUserParam.Expression, asmUserParam.Units)
                Else
                    ' Update the value of the existing parameter.
                    checkParam.Expression = asmUserParam.Expression
                End If
            Next
        End If
    Next

	iLogicVb.UpdateWhenDone = True
End Sub

 

The issue is that this code only spreads the parameters to it's child components (the ".ipt"s) but it doesn't spread the parameters to it's child assemblies (the ".iam"s don't receive the parameters). So, my question is; how can I modify this code so it populates the parameters to all it's child elements both the sub-asseblies and the child components?

 

Thanks for reading!

0 Likes
Reply
Accepted solutions (2)
188 Views
3 Replies
Replies (3)

WCrihfield
Mentor
Mentor
Accepted solution

Hi @tecnico3S7Z5.  It looks to me like this one 'check' in your code, at Line 14 is where the issue is.

If refDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
Dim partDoc As Inventor.PartDocument = refDoc

 You would need to eliminate that line of code, and also the 'End If' line of code that would be closing that 'If statement' out, later in the code.  Then, eliminate that next line after that line, where it is declaring a variable (partDoc) as a more specific document type (PartDocument).  However, if you do that, you will need to conduct a search & replace to find all instances of that 'partDoc' variable, and replace them with the 'refDoc' variable, to avoid those potential errors.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @tecnico3S7Z5
Welcome to the forum.

 

Here's am updated version of this addressing the point that WCrihfield made as well as the issue that would occur when there are true/false and text parameters present.

 

Hope that helps,
Curtis

 

If ThisDoc.Document.DocumentType <> Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("The active document must be an assembly.")
	Return
End If

Dim asmDoc As AssemblyDocument = ThisDoc.Document
For Each refDoc As Inventor.Document In asmDoc.AllReferencedDocuments
	Dim refDocUserParams As UserParameters = refDoc.ComponentDefinition.Parameters.UserParameters
	' Add the assembly parameters to the component document
	For Each asmUserParam As UserParameter In asmDoc.ComponentDefinition.Parameters.UserParameters
		Try
			newParam = refDocUserParams.Item(asmUserParam.Name)
		Catch ex As Exception
			If asmUserParam.Units.ToString = "Boolean" Or asmUserParam.Units.ToString = "Text" Then 
				newParam = refDocUserParams.AddByValue(asmUserParam.Name, asmUserParam.Value, asmUserParam.Units)
			Else
				newParam = refDocUserParams.AddByExpression(asmUserParam.Name, asmUserParam.Expression, asmUserParam.Units)
			End If
		End Try

		If Not newParam Is Nothing Then newParam.Expression = asmUserParam.Expression
	Next
Next

 

0 Likes

tecnico3S7Z5
Explorer
Explorer

Thank you everyone for your help! you saved me, really appreciate