先用下面的函数导出,查看有哪些可用的内部命令:
//输出控件命令,以便使用InventorApp.CommandManager调用
private void OutputControlCommand(Application application)
{
//application.CommandManager.ControlDefinitions
//导出至桌面1.txt并打开
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\1.txt";
using (StreamWriter sw = new StreamWriter(path))
{
foreach (ControlDefinition item in application.CommandManager.ControlDefinitions)
{
sw.WriteLine(string.Format("{0} - {1}", item.DisplayName, item.InternalName));
}
sw.Close();
}
System.Diagnostics.Process.Start(path);
}
结果就像这样
封装一个函数执行:
//执行内部命令
public void ExecuteCommand(string commandName)
{
try
{
app.CommandManager.ControlDefinitions[commandName].Execute();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "执行错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
例子:
//保存全部
ExecuteCommand("AppSaveAllCmd");