我正在使用 objectARX 并尝试创建一个新文档。我首先要做的是运行 AutoCad。
Process acadApp = new Process();
acadApp.StartInfo.FileName = "C:/Program Files/Autodesk/AutoCAD 2015/acad.exe";
acadApp.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
acadApp.Start();
然后问题是当我等到 Acad 的实例准备好时。由于 Autocad 窗口尚未准备好并且我无法创建 AcadApplication 实例,因此我无法使用 Process 类以他的名字获取进程。它仅在 Autocad 完全加载时才有效,所以我使用 .
bool checkInstance = true;
//This piece of pure shit listen for an Acad instnce until this is opened
while (checkInstance)
{
try
{
var checkinstance = Marshal.GetActiveObject("AutoCAD.Application");
checkInstance = false;
}
catch (Exception ex)
{
}
}
//Once the acad instance is opende The show starts
Thread.Sleep(12000);
Thread jili2 = new Thread(new ThreadStart(() => acadG.AcadGrid(Convert.ToInt32(grid.floorHeight), Convert.ToInt32(grid.floorWidth), grid.numFloors)));
jili2.Start();
// MessageBox.Show("I don't know why it was executed");
}
线程中运行的 acadGrid 方法在 AutoCad 中创建一个新文档,然后绘制一个网格。它有时工作有时不工作,当它工作时,它甚至会使用 50% 的 CPU。有时我得到这个例外。