suppress multiple part using vba

suppress multiple part using vba

Anonymous
Not applicable
581 Views
1 Reply
Message 1 of 2

suppress multiple part using vba

Anonymous
Not applicable

The code below is working fine for selecting 3 parts 

 

 

' To suppress a part

Public Sub AssemblyCount()

    ' Set reference to active document.

    ' This assumes the active document is an assembly

    Dim oDoc As Inventor.AssemblyDocument

    Set oDoc = ThisApplication.ActiveDocument

    Dim selset As SelectSet

    Dim compOcc As ComponentOccurrence

    oDoc.SelectSet.Clear

    MsgBox ("Select a Part or a Subassembly")

    Do Until oDoc.SelectSet.Count = 3

        DoEvents    ' Yield to other processes.

    Loop

    Set selset = oDoc.SelectSet

    Dim obj As Object

    For Each obj In selset

        If TypeOf obj Is ComponentOccurrence Then

               Set compOcc = obj

               compOcc.Suppress

        End If

    Next

    oDoc.SelectSet.Clear

End Sub

 

 

But i want to select multiple parts until i hit enter button after hitting enter button all the selected parts must be suppressed

 

I tried the Application.onkey 

 

Public enterWasPressed As Boolean

' To suppress a part

Public Sub AssemblyCount()

    ' Set reference to active document.

    ' This assumes the active document is an assembly

    Dim oDoc As Inventor.AssemblyDocument

    Set oDoc = ThisApplication.ActiveDocument

    Dim selset As SelectSet

    Dim compOcc As ComponentOccurrence

   

    oDoc.SelectSet.Clear

    MsgBox ("Select a Part or a Subassembly")

    enterWasPressed = False

    Do Until enterWasPressed = True

        DoEvents    ' Yield to other processes.

        Application.OnKey "{ENTER}", "recordEnterKeypress"

    Loop

 

 

    Set selset = oDoc.SelectSet

    Dim obj As Object

    For Each obj In selset

        If TypeOf obj Is ComponentOccurrence Then

               Set compOcc = obj

               compOcc.Suppress

        End If

    Next

    oDoc.SelectSet.Clear

End Sub

 

   

 

Sub recordEnterKeypress()

    enterWasPressed = True

End Sub

 

 

but i am getting runtime error '424' object required can anyone please help me to fix my issue

 

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

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

Application.OnKey seems to be a function available in Excel, etc, but I do not see it in Inventor.

 

Inside Inventor you'd have to subscribe to the KeyboardEvents objects, which provide OnKeyDown, OnKeyPress, OnKeyUp.

 

Easiest thing to test these things is inside the VBA environment, go View >> Object Browser, then serach for OnKey

 

Cheers, 



Adam Nagy
Autodesk Platform Services
0 Likes