- 积分
- 2248
- 明经币
- 个
- 注册时间
- 2011-12-29
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2015-3-3 10:42:34
|
显示全部楼层
public static void OpenCAD2012(string path,string cmd,bool closed)
{
const string progID = "AutoCAD.Application.18.2";
const string exePath = @"C:\Program Files\Autodesk\AutoCAD 2012 - Simplified Chinese\acad.exe";
AcadApplication acApp = null;
AcadDocument doc=null;
// Let's first check we don't have AutoCAD already running
try
{
acApp = (AcadApplication)Marshal.GetActiveObject(progID);
}
catch { }
if (acApp != null)
{
// MessageBox.Show("An instance of AutoCAD is already running.");
}
else
{
try
{
Process pr = Process.Start(exePath);
pr.WaitForInputIdle();
while (acApp == null)
{
try
{
acApp = (AcadApplication)Marshal.GetActiveObject(progID);
}
catch
{
Application.DoEvents();
}
}
}
catch (Exception ex)
{
MessageBox.Show("Cannot create or attach to AutoCAD object: " + ex.Message);
}
}
if (acApp != null)
{
acApp.Visible = true;
acApp.Documents.Open(path, false, null);
doc = acApp.ActiveDocument;
doc.SendCommand(cmd);
if (closed)
doc.Close(true);
}
}
}
这是我程序里打开CAD文档 并发出 命令的代码 ,打开几张图形时不会出现问题,图形一旦多了很有可能出现拒绝呼叫的问题!请高手指点!!!
我看到楼主实例里有个Interop.VBIDE.dll ,不知道楼主是用什么方式操作CAD的 ,希望能得到您详细指点!谢谢
|
|