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: 

VBA Macro to Toggle Enabled / Disabled Component

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
davidgwoolard
516 Views, 2 Replies

VBA Macro to Toggle Enabled / Disabled Component

Can someone provide a macro that will allow me to, after selecting a part or component, toggle whether it is enabled or disabled.  I would like this so that I can assign a keyboard shortcut to the macro, and then quickly enable/disable parts in an assembly.

 

Thank you for your help.

2 REPLIES 2
Message 2 of 3
YuhanZhang
in reply to: davidgwoolard

Here is the macro:

 

Sub ToggleOccuEnabled()
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
    
    If oDoc.DocumentType = kAssemblyDocumentObject Then
        Dim oAssy As AssemblyDocument
        Set oAssy = oDoc
        
        Dim oDef As AssemblyComponentDefinition
        Set oDef = oAssy.ComponentDefinition
        
        If oAssy.SelectSet.Count <> 0 Then
            Dim oObj As Object
            Set oObj = oAssy.SelectSet(1)
            
            If TypeName(oObj) = "ComponentOccurrence" Then
                Dim oOccu As ComponentOccurrence
                Set oOccu = oObj
                
                ' Toggle the Enabled
                oOccu.Enabled = Not (oOccu.Enabled)
                
            End If
        End If
    End If
        
    End
End Sub

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 3 of 3
davidgwoolard
in reply to: YuhanZhang

I copied the macro provided into my vba module, and then set a keyboard shortcut for the ToggleOccuEnabled macro.  It works like a charm.  Thank you.

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

Post to forums  

Autodesk Design & Make Report