Interrupting component placement after first occurrence is placed

Interrupting component placement after first occurrence is placed

j.haggenjos
Advocate Advocate
772 Views
2 Replies
Message 1 of 3

Interrupting component placement after first occurrence is placed

j.haggenjos
Advocate
Advocate

Hello all,

 

 

I'm developing an Add-In and I am facing an issue.

 

At some point in the process, I am placing a part with user interaction. The component placement is working correctly.

 

However, until the user hits the escape key or "right-click -> Done", each click will place a new occurrence of the component. I would like to prevent the user of placing multiple component.

 

In my main routine, I am using the command manager to place a component:

 

CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, FilePath)
CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute()

 

And using the OnNewOccurrence event handler I am trying to stop the command after the first item is placed.

 

I have tried the following:

 

Private Sub AssemblyEvents_OnNewOccurrence(...) Handles AssemblyEvents.OnNewOccurrence
    If BeforeOrAfter = EventTimingEnum.kAfter Then

        CommandManager.StopActiveCommand()
        'This will throw an exception 

        CommandManager.ControlDefinitions.Item("AppContextual_DoneCmd").Execute()
        CommandManager.ControlDefinitions.Item("AppContextual_CancelCmd").Execute()
        CommandManager.ControlDefinitions.Item("AppContextual_OKCmd").Execute()
        'Those three command seem to have no effect

    End If
End Sub

 

Is there any way to stop the AssemblyPlaceComponentCmd with the API?

0 Likes
Accepted solutions (1)
773 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Here are a couple more commands you can try:

"Done"

"AppNGX_CancelCmd" (cancels the command)

"AppNGX_OKCmd"  (commits the command)

Other than that, all I can think of is either using the SendKeys.SendWait("{ESC}") technique (which you may need to make sure you have the 'focus' of that dialog before using), or not using the command to invoke the built-in tool for adding components, and attempt to do it in a different way.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

j.haggenjos
Advocate
Advocate
Accepted solution

Thanks for the answer.

 

I tried the commands. They had no effect unfortunately.

 

I had tried simulating the escape key before. Following your post, I tried to make sure the inventor window was in focus. I stumbled upon this post and tried using postmessage. It didn't work either. However, the post also suggest to use:

 

CommandManager.ControlDefinitions.Item("AppSelectNorthwestArrowCmd").Execute

 

Which finaly had the result I was looking for. Interestingly, searching for "AppSelectNorthwestArrowCmd" lead me to this post from 2008 with the exact same issue and solution.

 

 

Thanks @WCrihfield for pushing me in the right direction with your post.

 

A special thanks to @ekinsb for his suggestion in the other post and for all the great content available here and elsewhere online.

0 Likes