Suppress command repeat with space bar (API)

Suppress command repeat with space bar (API)

Martin-Winkler-Consulting
Advisor Advisor
799 Views
2 Replies
Message 1 of 3

Suppress command repeat with space bar (API)

Martin-Winkler-Consulting
Advisor
Advisor

I am opening a WPF form from an Addin button with  .Show  (.ShowDialog is not wanted).
If I then make an entry in a text box in the form, the last command is repeated when the space bar is pressed (Inventor default setting) and the already opened form opens again.
How can I temporarily switch off the keyboard command "Repeat command" which is triggered by pressing the spacebar using the API? Or is it possible to delete the last command from memory so that pressing space do nothing?
I already have tried it with

InventorApp.CommandManager.ControlDefinitions("AppRestartCommand").Enabled = False


but that didn't work.
Do I have to catch the space key event? And if so, how could I do it?

Martin Winkler
CAD Developer
Did you find this post helpful? Feel free to like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature

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

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Martin-Winkler-Consulting 

Looking in to this I don't think its possible to disable the command. I do think however that you can get rid of the problem setting inventor to the owner of your window. I'm not very experienced in WPF forms but i think you should have a look here:

https://adndevblog.typepad.com/manufacturing/2015/11/wpf-window-inside-an-inventor-add-in.html

 

Especially the last few lines of code.

1. Set a reference to System.Windows.Interop.WindowInteropHelper

2.

// Could be a good idea to set the owner for this window
  // especially if used as modeless
  var helper = new WindowInteropHelper(wpfWindow);
  helper.Owner = new IntPtr(m_inventorApplication.MainFrameHWND);

  wpfWindow.Show(); 

The code is C# but I think you get the idea 🙂

Message 3 of 3

Martin-Winkler-Consulting
Advisor
Advisor
Accepted solution

@JhoelForshav 

thanks a lot, this was exactly i am searching for.

In Addition this post was helpful:

https://adndevblog.typepad.com/manufacturing/2012/06/space-entered-in-a-text-box-of-a-modeless-dialo...

 

And here is the C# class for getting the MainFrame from Inventor in VB.Net

Imports Inventor
Imports System.Windows.Forms

Public Class IVMainFrame
    Implements IWin32Window
    Public ReadOnly Property Handle As IntPtr Implements IWin32Window.Handle
        Get
            Return m_hWnd
        End Get
    End Property
    Private m_hWnd As Long
    Sub New(hWnd As Long)
        m_hWnd = hWnd
    End Sub
End Class

Sample for opening the form look like this:

'Reference is needed for WindowInteropHelper
Imports System.Windows.Interop
......
Sub button_Execute()
Dim buttonEx As New MyForm(InventorApp.ActiveDocument)
'Setting the owner of the form to the Inventor MainFrame
Dim helper As New WindowInteropHelper(buttonEx)
helper.Owner = New IntPtr(InventorApp.MainFrameHWND)
'Opening Form
buttonEx.Show()
End Sub

Martin Winkler
CAD Developer
Did you find this post helpful? Feel free to like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature