Addind Coments Through iLogic

Addind Coments Through iLogic

Anonymous
Not applicable
519 Views
3 Replies
Message 1 of 4

Addind Coments Through iLogic

Anonymous
Not applicable

Hello All,

 

I am wondering if there is a way to have to add iProperty Comments through iLogic? I am wanting to break down the assembly down to sub assemblies to parts.

 

Such as Main assembly is 001, sub assemblies start at 002 and then parts start whenever the sub assemblies end. So essentially the code would count through the files and count accordingly.

0 Likes
520 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

This is very possible, so just to be clear you want to add an iProperty to each assembly or part, with its value being the BOM level of that file?

0 Likes
Message 3 of 4

Anonymous
Not applicable

Yes, basically the main assembly will be 001 and then have it go through the structure BOM and then the PArts only BOM

0 Likes
Message 4 of 4

Anonymous
Not applicable

Hope this iLogic rule does what you need.

It will look for a custom parameter named "Level" in each assembly/part, add it if it doesn't exist and set its value to the BOM level of that item.

Let me know if you want this behaviour altered, you may not want the iProperty to be added to every item in your BOM, in which case can be easily fixed. 

 

Sub Main TraverseAssembly()
' Get the active assembly. 
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument 

Dim Level As Integer = 1
Dim myStr = Level.ToString("D3") 

Try
    'try to set iProperty value
    oAsmDoc.PropertySets.Item("Inventor User Defined Properties").Item("Level").Value = myStr
Catch
    'catch error when iProperty doesn't exist and create it
    oAsmDoc.PropertySets.Item("Inventor User Defined Properties").Add("","Level")
    'set iProperty value
    oAsmDoc.PropertySets.Item("Inventor User Defined Properties").Item("Level").Value = myStr
End Try

' Call the function that does the recursion. 
Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, Level + 1) 

End Sub

Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer) 
    ' Iterate through all of the occurrence in this collection.  This 
    ' represents the occurrences at the top level of an assembly. 
    Dim oOcc As ComponentOccurrence 
    For Each oOcc In Occurrences 
    
        'define custom property collection
        oCustomPropertySet = oOcc.Definition.Document.PropertySets.Item("Inventor User Defined Properties")
        
        Dim myStr = Level.ToString("D3") 
        
        Try
            'try to set iProperty value
            oCustomPropertySet.Item("Level").Value = myStr
        Catch 
            'catch error when iProperty doesn't exist and create it
            oCustomPropertySet.Add("","Level")
            'set iProperty value
            oCustomPropertySet.Item("Level").Value = myStr
        End Try

        ' Check to see if this occurrence represents a subassembly 
        ' and recursively call this function to traverse through it. 
        If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then 
            Call TraverseAssembly(oOcc.SubOccurrences, Level + 1) 
        End If 
    Next 
End Sub

 

0 Likes