- 积分
- 2248
- 明经币
- 个
- 注册时间
- 2011-12-29
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
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);
}
}
}
网上有说在启动前让进程sleep(1000)的方法,但是如果批量打开cad的还是会出现cad拒绝呼叫的情况,有没有像vb6那样可以完美打开CAD的方法?
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|