You may want to run Inventor commands directly in you iLogic code, without having to find and reference them in the API. This is made possible through the “Command Manager” in the API.
The Command Manager lets you run any command that is visible in the Inventor interface (and a few hidden commands as well). Think of it as a “Push Button” option for running code. If you can see the button in Inventor, you can effectively click on that icon in your iLogic code.
Here is an example of the “Zoom All” command in action.
The code is one line, with the command we want to run “AppZoomAllCmd” included.
This is possibly not the best example, as the code to do this traditionally in iLogic is ThisApplication.ActiveView.Fit, but stick with me, this is still very handy!
Any command that does not require additional inputs, like specifying a size etc. is easy to run using this method. But you might be wondering how to get hold of a list of commands? I’ve published a set of commands that I use, which you can download in .txt format here. I’ll explain how to generate your own list further down.
The txt file is in the format shown below, with the “App Name” on the left and any available description on the right. To find a command, I usually use the “Find” command in Notepad (Ctrl+F).
Here’s a quick example of some visibility commands that have been added to an array, and are being run from an input list box.
This is the iLogic code used in the animation above.
Dim oCommander As New ArrayList oCommander.Add("AppZoomAllCmd") oCommander.Add("AppUserWorkAxesVisibilityCmd") oCommander.Add("AppUserWorkPlanesVisibilityCmd") oCommander.Add("AppUserWorkPointsVisibilityCmd") UnofficialInventor = InputListBox("Prompt", oCommander, UnofficialInventor, Title := "Title", ListName := "List") If UnofficialInventor = "" Then : Return : Else Call ThisApplication.CommandManager.ControlDefinitions.Item(UnofficialInventor).Execute End If
Now before I share my rule for getting to these commands, exercise some caution, test this carefully on non-production files, and be prepared to run into problems, like trying to run a command from my list, for a command that you dont have loaded (i.e Inventor CAM commands, or other add-ins), or crashing because YOU have asked the software to do something silly!.
Remember that this is just one tool in your coding toolbox, it certainly does not fit every situation, but can be a useful additon to your current toolset. This workflow only “pushes” command’s the button, most workflows will require additional input, such as specifying the size of a fillet, or choosing which geometry to constrain.
Brian Ekins, formerly of Autodesk, wrote a very interesting post on this topic, I suggest that you give it a read. The code below is based on Bryan’s.
Here’s the iLogic code to extract all of your Inventor commands:
'Code by @ClintBrown3D 'Originally posted at https://clintbrown.co.uk/ilogic---running-commands-using-the-api 'Also See https://modthemachine.typepad.com/my_weblog/2009/03/running-commands-using-the-api.html Dim oCommandMgr As CommandManager ' Get the CommandManager object. oCommandMgr = ThisApplication.CommandManager ' Get the collection of control definitions. Dim oControlDefs As ControlDefinitions oControlDefs = oCommandMgr.ControlDefinitions oWrite = System.IO.File.CreateText("C:\Temp\CommandNames.txt")'Create and write to a text file For Each oControlDef In oControlDefs ' iterate through the commands and write to file oWrite.WriteLine(oControlDef.InternalName & " " & oControlDef.DescriptionText) Next oWrite.Close() ' Close the temp file ThisDoc.Launch("C:\Temp\CommandNames.txt")'open the file