Message 1 of 2

Not applicable
05-29-2019
08:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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?
Solved! Go to Solution.