Created
July 7, 2019 18:10
-
-
Save abc126/5684a06b0c76aa4cb683e609c833f322 to your computer and use it in GitHub Desktop.
SendACommandToAutoCAD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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