Q:
I need to find the internal name of a command so I can run it from a macro. Is there an example showing how to find the internal name?
A:
The CommandManager object allows you to run commands as if they were executed from the user interface. The internal name needed (string) for the execute method is not documented in the help file. Here is a VB.Net example that will print out a list of Inventor commands containing "WorkFeatures" in their name:
Sub FindCommandByInternalName(
ByVal app As Inventor.Application,
ByVal CommName As String)
'Gets CommandManager's Control Definitions
Dim oControlDefs As ControlDefinitions
oControlDefs = app.CommandManager.ControlDefinitions
'Iterates trough all Control Definitions and prints the InternalName and
'DescriptionText of commands that match a part of the input string
Dim oControlDef As ControlDefinition
For Each oControlDef In oControlDefs
If InStr(oControlDef.InternalName, CommName) <> 0 Then
System.Console.WriteLine(
"[Internal Name]" & oControlDef.InternalName &
" [Description]" & oControlDef.DescriptionText)
End If
Next
End Sub
Sub TestCommandName()
FindCommandByInternalName(m_inventorApp, "AppAllWorkfeaturesCmd")
'This will be printed out in the output window:
'[Internal Name]AppAllWorkfeaturesCmd
'[Description]Display all work features (origin and user)
End Sub
Sub TestCommand()
m_inventorApp.CommandManager.ControlDefinitions.Item
("AppAllWorkfeaturesCmd").Execute()
End Sub