Skip to content

Instantly share code, notes, and snippets.

@abc126
Created July 7, 2019 18:10
Show Gist options
  • Select an option

  • Save abc126/5684a06b0c76aa4cb683e609c833f322 to your computer and use it in GitHub Desktop.

Select an option

Save abc126/5684a06b0c76aa4cb683e609c833f322 to your computer and use it in GitHub Desktop.
SendACommandToAutoCAD
public static void SendACommandToAutoCAD(string command)
{
MgdAcDocument doc = MgdApplication.DocumentManager.MdiActiveDocument;
if(doc == null)
{
MessageBox.Show("当前无活动文档,请新建或切换至活动文档后再执行命令", "无法获取活动文档", MessageBoxButtons.OK, MessageBoxIcon.Stop);
return;
}
// 根据是否有命令运行决定esc的数量
string esc = "";
string cmds = (string)MgdApplication.GetSystemVariable("CMDNAMES");
if (cmds.Length > 0)
{
int cmdNum = cmds.Split(new char[] { '\'' }).Length;
for (int i = 0; i < cmdNum; i++)
{
esc += '\x03';
}
}
doc.SendStringToExecute(esc + "_." + command + " ", true, false, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment