07-22-2024
02:34 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
07-22-2024
02:34 PM
I typically just use a try/catch to try and set the value, and then catch the error when it does not exist and add it.
Keep in mind that drawings and models have the user parameter set organized a bit differently, since drawings do not contain a component definition.
If Thisapplication.ActiveDocument.DocumentType = DocumentTypeenum.kDrawingDocumentObject Then oUserParams = ThisDoc.Document.Parameters.UserParameters Else oUserParams = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters End If dValue = 99 Try Parameter( "Foo") = dValue Catch oParam = oUserParams.AddByValue("Foo", dValue, UnitsTypeEnum.kDefaultDisplayLengthUnits) End Try
If you are working with assembly occurrences, then something like this will work
Dim oOcc As ComponentOccurrence = Component.InventorComponent("MyPart") oUserParams = oOcc.Definition.Document.ComponentDefinition.Parameters.UserParameters dValue = 99 Try Parameter(oOcc.Name, "Foo") = dValue Catch oParam = oUserParams.AddByValue("Foo", dValue, UnitsTypeEnum.kDefaultDisplayLengthUnits) End Try