error while sending parameters from assembly to parts

error while sending parameters from assembly to parts

Anonymous
Not applicable
368 Views
1 Reply
Message 1 of 2

error while sending parameters from assembly to parts

Anonymous
Not applicable

This is my code:

Public Sub Main()
          CopyUserParamsParts()
          CopyUserParamsAssies()
          iLogicVb.UpdateWhenDone = True
End Sub
 
Private Sub CopyUserParamsParts()
    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 oDoc As Inventor.Document = ThisDoc.Document
                       Dim partDoc As Inventor.PartDocument = refDoc
            Dim refDocUserParams As UserParameters = partDoc.ComponentDefinition.Parameters.UserParameters
                       
                       ' skip Content Center files
                       If refDoc.PropertySets.PropertySetExists ("ContentCenter") = False Then
                               
                    ' 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.
						If asmUserParam.Units = "Text" Then	
							refDocUserParams.AddByExpression(asmUserParam.Name, asmUserParam.Expression, UnitsTypeEnum.kTextUnits)
						Else
                            refDocUserParams.AddByExpression(asmUserParam.Name, asmUserParam.Expression, asmUserParam.Units)
						End If	
						
                        Else
                            ' Update the value of the existing parameter.
                            checkParam.Expression = asmUserParam.Expression
                        End If
               Next
               End If
               End If
    Next
End Sub
 
Private Sub CopyUserParamsAssies()
    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 assembly documents.
        If refDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
                       Dim oDoc As Inventor.Document = ThisDoc.Document
                       Dim AssyDoc As Inventor.AssemblyDocument = refDoc
            Dim refDocUserParams As UserParameters = AssyDoc.ComponentDefinition.Parameters.UserParameters
                               
                    ' Add the assembly parameters to the subasembly.
                    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.
                      	If asmUserParam.Units = "Text" Then	
							refDocUserParams.AddByExpression(asmUserParam.Name, asmUserParam.Expression, UnitsTypeEnum.kTextUnits)
						Else
                            refDocUserParams.AddByExpression(asmUserParam.Name, asmUserParam.Expression, asmUserParam.Units)
						End If	
						
						Else
                            ' Update the value of the existing parameter.
                            checkParam.Expression = asmUserParam.Expression
                        End If
               Next
        End If
    Next
End Sub

If I run this code on just normal user parameters, it works, but if I do this with Text parameters, it fails and gives me back error: 

Error in rule: Push parameters V2, in document: autolift.iam

De parameter is onjuist. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

Can anybody help me?

0 Likes
Accepted solutions (1)
369 Views
1 Reply
Reply (1)
Message 2 of 2

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

I am not sure what you are trying to do, but I would modify the code a bit to start working, I would leave it more or less like that.

 

Sub Main()
If ThisDoc.Document.DocumentType <> Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
        MsgBox("The active document must be an assembly.")
      Exit Sub
End If
          CopyUserParamsToRefDoc()
          iLogicVb.UpdateWhenDone = True
End Sub

Sub CopyUserParamsToRefDoc()

	Dim asmDoc As Inventor.AssemblyDocument = ThisDoc.Document      
	For Each refDoc As Inventor.Document In asmDoc.AllReferencedDocuments
	' Look for part documents.
		Dim refDocUserParams As UserParameters = refDoc.ComponentDefinition.Parameters.UserParameters
		' skip Content Center files
		If refDoc.PropertySets.PropertySetExists ("ContentCenter") = False Then
			' 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
				Try
				checkParam = refDocUserParams.Item(asmUserParam.Name)

					checkParam.Expression = asmUserParam.Expression
				Catch
					Try
						refDocUserParams.AddByExpression(asmUserParam.Name, asmUserParam.Expression, asmUserParam.Units)
					Catch
						refDocUserParams.AddByValue(asmUserParam.Name, asmUserParam.Expression, asmUserParam.Units)
					End Try
				End Try
			Next
		End If
	Next
End Sub

 I hope it works for what you need. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes