Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Toggle Assembly Component Visibility According to Custom iProperty

0 REPLIES 0
Reply
Message 1 of 1
vampelas
387 Views, 0 Replies

Toggle Assembly Component Visibility According to Custom iProperty

Hi,

 

I recently had a customer request for an iLogic code that would look through the components of an assembly and pick on a Custom iProperty called "Visibility", and toggle the component Visibility according to the property vaule "On" or "Off".

 

When I asked the customer why not just use the LOD functionality in Inventor he advised that this working rather slow for them and was not exactly what they where looking for.

 

Anyway, I just finished that code and thought I would share this in case it is needed as a whole or as an example on how to access the comoponents occurence iProperties.

 

'Set Assembly Component Deifiniton
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
    Try
        'MessageBox.Show(oOccurrence.Name, "iLogic")
        
        'get the selected item document occurrence name
        doc = oOccurrence.Definition.Document
        
        'get the path and file name of the selected item
        CurFileName = doc.FullFileName
    
        'MessageBox.Show(CurFileName, "iLogic")
    
        'Get the Document from the occurrence
        docFile = oOccurrence.definition.Document
    
        'Find position in full filename path string where component filename begins   
        FNamePos = InStrRev(doc.FullFileName, "\", - 1)
    
        'Strip off filename path string and set docFName to just the component's file name  
        docFName = Mid(doc.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)
        
        'MessageBox.Show(docFName, "iLogic")
        
        Dim oName As String
        'Set oName to the current component occurrence name
        oName = oOccurrence.Name
    
        Try
            'Check if custom iProperty "Vibility" is ON
            If iProperties.Value(docFName, "Custom", "Visibility") = "On" Then    
                
                'MessageBox.Show(oName & " " & "=" & "On", "Title")
                
                'Do NOT Suppress component
                Component.Visible(oName) = True
                
            Else If iProperties.Value(docFName, "Custom", "Visibility") = "Off" Then
            
                'MessageBox.Show(oName & " " & "=" & "OFF", "Title")
                
                'Suppress Component
                Component.Visible(oName) = False
                
            End If
            
            'Move to next component if "Visibility" iProperty is not present on file
            Catch ex As Exception
            
        End Try
        
        'Move to next component if component is already suppressed
        Catch ex As Exception
    End Try
Next

 

 

Hope this comes handy anyway...


Best Regards,

Vas

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report