First component material substitute
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
v Inventor Pro 2019,
I am trying to set an iLogic rule to create a custom property 'iMATERIAL' in assembly parts that reads the material from its first component.
In parallel I am setting a substitute condition on the parts list to show the 'iMATERIAL' property instead of the 'MATERIAL' when it exists.
In essence the logic is most assembly materials are defined from their first component material (not always true but good enough for me)
The code I have so far is the following (which I intend to trigger before save on .iam files) :
Sub Main() If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then Exit Sub End If Dim propertyName As String = "iMATERIAL" customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties") Try prop = customPropertySet.Item(propertyName) Catch ' Assume error means not found customPropertySet.Add("", propertyName) End Try Dim oSource As Document = ThisApplication.ActiveDocument.ComponentDefinition.Occurrences(1).Definition.Document If oSource.DocumentType <> kAssemblyDocumentObject Then iProperties.Value("Custom", propertyName) = oSource.PropertySets.Item("Design Tracking Properties").Item("Material").Value Else iProperties.Value("Custom", propertyName) = oSource.PropertySets.Item("Inventor User Defined Properties").Item("iMATERIAL").Value End If ThisDoc.Document.Update End Sub
The code runs like a charm on regular parts and assemblies.
But I run into errors when iParts/iAssemblies are involved...
I know their properties are defined at the factory level but how to deal with those cases in the code is beyond me...
Any suggestions ?
Regards