I've looked around and done some research on this and it seems possible just I can't figure out how to do it.
I'm looking to send keystrokes programmically using iLogic as if the keys were actually being pressed. I just want to send a simple set of keys like "QQ".
Does anybody know how I would do this through iLogic?
Even if it is an improper method of programming, is there anyone who can tell me how to do this
Please create one part document first. When copying the code lines below in VBA Editor dialog and running macro, it will work fine, and this simulates to press the "E" key to create extrusion.
Declare Function PostMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_KEYDOWN As Long = &H100
Private Const WM_KEYUP = &H101
Dim FT_hWnd As Long
FT_hWnd = FindWindow(vbNullString, ThisApplication.Caption)
Call PostMessage(FT_hWnd, WM_KEYDOWN, Asc("E"), 0&)
Call PostMessage(FT_hWnd, WM_KEYUP, Asc("E"), 0&)
Wow, thank you very much!
I've been researching and researching on how to do this and have never come close to anything that looks like this.
The code worked great when I manually go in and run the macro. In the end, I would like to activate it and run it through an iLogic Rule so I can control when to use it.
I assumed it was as simple as using the snippet
Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 1121 StartFragment: 314 EndFragment: 1089 StartSelection: 314 EndSelection: 314
SyntaxEditor Code Snippet
InventorVb.RunMacro("DocumentProject", "Module1", "Main")
But it doesn't seem to be working
You can use Windows (Win32) code directly in an iLogic rule, instead of running a VBA macro. See the attached rule. I think if you added the call to SetFocus in the VBA code, the VBA macro would also work from an iLogic rule.
However, this rule won't work if it is triggered to run by a parameter change that is made in the Parameters dialog.
If you want to send a key to start an Inventor command, you can do it more easily with the Inventor API call ControlDefinition.Execute or ControlDefinition.Execute2.
I attempted to post the previous code directly into iLogic but it did not work. The only issue with the code you've provided is that it can only use one character. A little fiddling around with it let me find out that if I use the "PostMessage" line twice, it will use two characters.
I'm new to programming and unsure where I would use the ControlDefinition.Execute command. But the code you provided does work! Thank You!
Unfortunately I have but one more question, I thought I knew how to do this but apparently I do not.
Is it possible to access the "Customize" dialog box through code and change the shortcut keys? I would like to do this as a check and to insure that the correct keys I input to the code are indeed what the user has set. Or, save the string they have, and input the characters I desire, then re-input the previous shortcut that the user originally had.
Just for clarity, this is (as far as I know how to access it) Tools Tab > Customize > Keyboard Tab >... And then the command I'm trying to access, for helpfulness, lets say I'm trying to change the Command Name: "Constraint..." from Keys: "C" to Keys: "PP"
Instead of working with the particular command shortcut keys, it's better to start a command with code like this:
Dim oControlDef As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.
That will start the Constraint command.
You can get the shortcut keys for a command: it's available as the DefaultShortcut or OverrideShortcut property on the ControlDefinition object. But if you have a ControlDefinition object (as in the code above), you might as well just Execute it instead of worrying about the keys.
You need to know the internal name of the command. I attached a list of available command names.
The document you provided will definitly help for future coding as I'm learning how to do so. Thank you very much for providing me with this.
Unfortunately, where my issue lies is that I am working with an Add-In from an outside source. I will try to see if I can find the "internal name" given for this, but that is the reason why I am trying to use keys to open the dialog box. I have done quite a bit of research and found that I need to reference the .dll (which I found) as well as use the dialog box file (which I did not find).
So my next thought is to use the shortcut keys to open the dialog box as you can customize this command
Here is a rule that will list the internal command name for all add-in commands. It will save the list to C:\InventorCommands.txt. You should be able to find your command in there.
Wow, you just did 2 weeks worth of researching and digging in 5 seconds with those codes...
Thank you very much Mike! Five steps closer to model and drawing automation!