disable the Inventor "repeat last action" in AddIn

disable the Inventor "repeat last action" in AddIn

vandrakonZ
Participant Participant
915 Views
10 Replies
Message 1 of 11

disable the Inventor "repeat last action" in AddIn

vandrakonZ
Participant
Participant

Hi @Anonymous,

 

I have created an AddIn for Inventor, where I'm asking the user to provide some input (string) in a textbox of the UI.

Everything works well as long as the string does not contain any "Space" or the user doesn't press "Enter". In these case the AddIn is starting again as second instance --> because that was the last action for Inventor.

 

How to disable this feature of Inventor as long as the PlugIn is running?

Many thanks in advance.

0 Likes
Accepted solutions (1)
916 Views
10 Replies
Replies (10)
Message 2 of 11

yuzeaa
Advocate
Advocate

I will give you an example which can be tested in ilogic,but I won't explain  for it.

AddReference "System.Drawing"
AddReference "System.Windows.Forms"
Imports System.Windows.Forms
Class ThisRule
	Sub main
		Dim wrapper = New HwndWrapper(ThisApplication.MainFrameHWND)
        Dim dialog As New dialog1
        dialog.Show(wrapper)
	End Sub
End Class

Public Class dialog1
	#Region "Designer generated"
	Inherits System.Windows.Forms.Form
	Public Sub New()
	InitializeComponent()
	End Sub
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub
	 Private components As System.ComponentModel.IContainer

    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()
        Me.OK_Button = New System.Windows.Forms.Button()
        Me.Cancel_Button = New System.Windows.Forms.Button()
		Me.DataGridView1 = New System.Windows.Forms.DataGridView()
		Me.Column1 = New System.Windows.Forms.DataGridViewTextBoxColumn()
        Me.Column2 = New System.Windows.Forms.DataGridViewTextBoxColumn()
        Me.Column3 = New System.Windows.Forms.DataGridViewTextBoxColumn()
        Me.TableLayoutPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'TableLayoutPanel1
        '
        Me.TableLayoutPanel1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.TableLayoutPanel1.ColumnCount = 2
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
        Me.TableLayoutPanel1.Controls.Add(Me.OK_Button, 0, 0)
        Me.TableLayoutPanel1.Controls.Add(Me.Cancel_Button, 1, 0)
        Me.TableLayoutPanel1.Location = New System.Drawing.Point(746, 245)
        Me.TableLayoutPanel1.Name = "TableLayoutPanel1"
        Me.TableLayoutPanel1.RowCount = 1
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
        Me.TableLayoutPanel1.Size = New System.Drawing.Size(146, 27)
        Me.TableLayoutPanel1.TabIndex = 0
        '
        'OK_Button
        '
        Me.OK_Button.Anchor = System.Windows.Forms.AnchorStyles.None
        Me.OK_Button.Location = New System.Drawing.Point(3, 3)
        Me.OK_Button.Name = "OK_Button"
        Me.OK_Button.Size = New System.Drawing.Size(67, 21)
        Me.OK_Button.TabIndex = 0
        Me.OK_Button.Text = "Apply"
        '
        'Cancel_Button
        '
        Me.Cancel_Button.Anchor = System.Windows.Forms.AnchorStyles.None
        Me.Cancel_Button.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Cancel_Button.Location = New System.Drawing.Point(76, 3)
        Me.Cancel_Button.Name = "Cancel_Button"
        Me.Cancel_Button.Size = New System.Drawing.Size(67, 21)
        Me.Cancel_Button.TabIndex = 1
        Me.Cancel_Button.Text = "Cancel"
        	
		
		Me.DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
        Me.DataGridView1.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.Column1, Me.Column2, Me.Column3})
        Me.DataGridView1.Location = New System.Drawing.Point(62, 34)
        Me.DataGridView1.Name = "DataGridView1"
        Me.DataGridView1.RowTemplate.Height = 23
        Me.DataGridView1.Size = New System.Drawing.Size(353, 59)
        Me.DataGridView1.TabIndex = 1
		
		'Column1
        '
        Me.Column1.HeaderText = "Column1"
        Me.Column1.Name = "Column1"
        '
        'Column2
        '
        Me.Column2.HeaderText = "Column2"
        Me.Column2.Name = "Column2"
        '
        'Column3
        '
        Me.Column3.HeaderText = "Column3"
        Me.Column3.Name = "Column3"
        '

        '
        Me.AcceptButton = Me.OK_Button
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.CancelButton = Me.Cancel_Button
        Me.ClientSize = New System.Drawing.Size(904, 283)
        Me.Controls.Add(Me.TableLayoutPanel1)
		Me.Controls.Add(Me.DataGridView1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "dialog1"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "dialog1"
        Me.TableLayoutPanel1.ResumeLayout(False)
        Me.ResumeLayout(False)
    End Sub
    Friend WithEvents TableLayoutPanel1 As System.Windows.Forms.TableLayoutPanel
    Friend WithEvents OK_Button As System.Windows.Forms.Button
    Friend WithEvents Cancel_Button As System.Windows.Forms.Button
	Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView
    Friend WithEvents Column1 As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents Column2 As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents Column3 As System.Windows.Forms.DataGridViewTextBoxColumn
#End Region
    Private Sub OK_Button_Click(sender As System.Object,e As System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(sender As System.Object,e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub
End Class

Class HwndWrapper
		Implements IWin32Window
		Private ReadOnly m_hWnd As IntPtr
		
		Public Sub New(ByVal hWnd As IntPtr)
			m_hWnd = hWnd
		End Sub

		Public Sub New(ByVal hWnd As Integer)
			m_hWnd = CType(hWnd, IntPtr)
		End Sub

		Public ReadOnly Property Handle As IntPtr Implements IWin32Window.Handle
			Get
				Return m_hWnd
			End Get
		End Property
End Class
Message 3 of 11

WCrihfield
Mentor
Mentor

Hi @vandrakonZ.  I do not believe the 'repeat last command' functionality is dictated by a specific add-in.  It was created and integrated into Inventor's 'behavior' by Autodesk.  It is an actual ControlDefinition named "AppRepeatCmd", that can be executed.  Its ClientID has no value.  If there was a ClientID associated with it, that would indicate the add-in (ApplicationAddIn) that created that command.  Because it is a ControlDefinition, we can map it into our Marking Menu and/or specify a keyboard shortcut for it.  I do not believe that we can avoid it altogether.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 11

Frederick_Law
Mentor
Mentor

I'll say there is something wrong with your addin.

Addin and active window should get UI scope and process key entry.

Not IV.

Your addin is passing keys to IV.

 

I have this addin for over 10 years:

Addin-01.jpg

No problem using Space and Enter.

Message 5 of 11

nmunro
Collaborator
Collaborator

Is the UI for your add-in contained within a dockable panel? If so, keyboard handling is functionally broken (since IV2018) with IV handling some keystrokes while allowing others to be handled by the add-in. Writing your own key handler subclass for each control was the suggested route to avoid this, not an easy task.

        


https://c3mcad.com

Message 6 of 11

vandrakonZ
Participant
Participant

Hi @ Frederick_Law,

many thanks for your reply.

 

in my AddIn I'm just creating a new WPF window, where I have several buttons and textboxes.

What exactly do you mean by Scope of UI? are talking about Inputscope for the textboxes?

 

Could you please  give me a hint!?!?

0 Likes
Message 7 of 11

yuzeaa
Advocate
Advocate
Accepted solution

20231214181036.png

Message 8 of 11

vandrakonZ
Participant
Participant

Hi yuzeaa,

 

works perfectly as requested. Many Thanks.

 

0 Likes
Message 9 of 11

vandrakonZ
Participant
Participant
many thanks, you pushed me in the right direction...
0 Likes
Message 10 of 11

Frederick_Law
Mentor
Mentor

When a window/dialog is opened and active, it'll take all the input from mouse and keyboard.

Other windows should not get those input.  Unless they are watching or the active window programmed to pass them.

 

I didn't use WPF, I was using System.Windows.Forms in VS.

WindowsForms-01.jpg

Message 11 of 11

vandrakonZ
Participant
Participant

Hi @Anonymous,

many thanks for the quick and profound support.

It is always helpful to get other ideas and different view o a topic.

💪👍

0 Likes