First component material substitute

First component material substitute

benjamin.herinckx
Contributor Contributor
296 Views
1 Reply
Message 1 of 2

First component material substitute

benjamin.herinckx
Contributor
Contributor

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

0 Likes
297 Views
1 Reply
Reply (1)
Message 2 of 2

chandra.shekar.g
Autodesk Support
Autodesk Support

@benjamin.herinckx,

 

There are few questions on iPart/iAssembly like.

 

  1. Is iPartmember/iAssemblymemeber used in assembly?
  2. Is "iMATERIAL" property defined in iPartMember/iAssemblyMember or iPartFactory/iAssemblyFactor?

Can you please provide non confidential sample assembly which contains iPart and iAssembly at first occurrence?

 

Thanks and regards,

 

 

 

 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes