【发布时间】:2014-11-03 16:31:54
【问题描述】:
您好,我有一个要求,我必须打开存储在 C:\Temp 文件夹中的图形文件。 我尝试了以下代码
public void launchacad(string pth) //pth is the path to the .DWG file
{
const string progID = "AutoCAD.Application.19.1";
const string exePath = @"C:\Program Files\Autodesk\AutoCAD 2014\acad.exe";
AcadApplication acApp = null;
try
{
acApp =
(AcadApplication)Marshal.GetActiveObject(progID);
}
catch { }
if (acApp != null)
{
MessageBox.Show("An instance of AutoCAD is already running.");
}
else
{
try
{
ProcessStartInfo psi =new ProcessStartInfo(exePath);
psi.WorkingDirectory = @"C:\Temp";
psi.Arguments = pth;
Process pr = Process.Start(psi);
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.ActiveDocument.SendCommand("_MYCOMMAND ");
}
}
但是当我使用 CMD.exe 并键入时,Autocad 会弹出一条错误消息,提示 Cannot find the specified drawing.
"C:\Program Files\Autodesk\AutoCAD 2014\acad.exe" "C:\Temp\41 Stabd.dwg" It opens Autocad with the file(41 Stand.dwg) open.
我不明白我在哪里犯了错误。谁能帮帮我。
【问题讨论】:
-
如果 AutoCAD 是与“.dwg”文件关联的程序,您是否尝试过仅打开该文件?
Process.Start(@"C:\Temp\41 Stabd.dwg"); -
@GrantWinney 哦,是的,它正在使用此命令打开。但是,如果该文件与 Trueview 等其他应用程序或其他应用程序相关联,那么呢??
-
@GrantWinney pth="C:\Temp\41 Stand.dwg"
-
@GrantWinney naah 它的 Stand.dwg。这是一个错字。
-
@GrantWinney 无论如何,非常感谢。至少它开始打开 DWG。谢谢