public GcadApplication App;
public GcadDocument Doc;
public bool connect_autocad()
{
try
{ // if AUTOCAD alread open,then conenct it.
App = (GcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
}
catch
{ // if AUTOCAD don't open then open it.
try
{
App = new GcadApplication();
}
catch (Exception e) { Console.WriteLine(e); return false; }
}
App.Visible = true;
return true;
}
public void Open_Cad(CadFileInfo filePath)
{
try
{
//連接CAD
if (connect_autocad() == false)
{
return;
}
//關閉已打開文檔
App.Documents.Close();
Doc = App.Documents.Open(filePath.filePath);
//App.ZoomExtents();
Doc.SendCommand("filedia\r0\r");
Doc.SendCommand("GetTk\r");
}
catch
{
}
}