- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The attached code is something I found that copies user-defined parameters from parts in an assembly to the assembly user-defined parameters, but I was hoping someone could help adapt this so that instead of pulling "all" user-defined parameters from "all" the parts in an assembly, it could be changed to ask which part or parts to pull from?
If I'm being very specific, it would be nice if this could be told to reference a specific part(s) and if the rule is ran and additional user parameters are added to those parts at a later time that the assembly rule can be ran again and if ran again it would only add user define parameters not already found in the assembly parameters.
Here's the iLogic code for the part parameters to be copied to the assembly, thanks to @JhoelForshav
Dim asmDoc As Inventor.AssemblyDocument = ThisDoc.Document For Each refDoc As Inventor.Document In asmDoc.AllReferencedDocuments Dim refDocUserParams As UserParameters = asmDoc.ComponentDefinition.Parameters.UserParameters 'Look for part documents. If refDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then Dim partDoc As Inventor.PartDocument = refDoc 'Add the part parameters to the assembly. For Each partUserParam As UserParameter In refDoc.ComponentDefinition.Parameters.UserParameters 'Check to see if the parameter already exists. Dim checkParam As UserParameter = Nothing Try checkParam = refDocUserParams.Item(partUserParam.Name) Catch checkParam = Nothing End Try If checkParam Is Nothing Then 'Create the missing parameter. Try refDocUserParams.AddByExpression(partUserParam.Name, partUserParam.Expression, partUserParam.Units) Catch refDocUserParams.AddByValue(partUserParam.Name, partUserParam.Value, partUserParam.Units) End Try Else 'Update the value of the existing parameter. Try checkParam.Expression = partUserParam.Expression Catch checkParam.Value = partUserParam.Value End Try End If Next End If Next
Solved! Go to Solution.