Message 1 of 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good day,
I got this code from a Forum that @BrianEkins answered to copy all user parameter from assembly to parts in that assembly.
I added an event trigger on asm to any user parameter changes so everytime I change something everyting in the parts update as well.
Now with 2022 Model states, as soon as I add a model state to a part it gives an error: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
Im starting with iLogic as I have seen it really can do wonders.
Can anyone advise me how to change code?
Thank you
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 End Sub
Solved! Go to Solution.