public static void Main(string[] args) { if (args.Length != 0) { arquivos = args; } else { SelectFiles(); } AcadApplication acApp = null; try { acApp = Marshal.GetActiveObject("AutoCAD.Application") as AcadApplication; } catch { MessageBox.Show("Não foi possível abrir o AutoCAD"); } foreach (var desenho in arquivos) { AcadDocument doc; try { doc = acApp.Documents.Open(desenho, false, string.Empty); AcadModelSpace modelSpace = doc.ModelSpace; } catch (Exception ex) { MessageBox.Show("Não foi possível abrir o desenho " + desenho + ex); break; } doc.SendCommand("ELL "); doc.PurgeAll(); doc.PurgeAll(); doc.PurgeAll(); acApp.ZoomExtents(); doc.Save(); doc.Close(); } }
private bool OpenDwgAndProcessFile(string Path) { if (App != null) { AcadDocument Doc = this.App.Documents.Open(Path); App.ZoomExtents(); App.ZoomScaled(0.6, AcZoomScaleType.acZoomScaledRelativePSpace); Doc.Save(); Doc.Close(); return(true); } else { MessageBox.Show("请先点击截面上的AutoCAD启动按钮再使用该软件"); return(false); } }
public static void Launch_Autocad() { //object res; // "AutoCAD.Application.17" uses 2007 or 2008, // whichever was most recently run // "AutoCAD.Application.17.1" uses 2008, specifically // "AutoCAD.Application.16.2" uses 2006 // "AutoCAD.Application.18" uses 2010 const string progID = "AutoCAD.Application.18"; AcadApplication acApp = null; try { acApp = (AcadApplication)Marshal.GetActiveObject(progID); } catch { try { Type acType = Type.GetTypeFromProgID(progID); acApp = (AcadApplication)Activator.CreateInstance(acType, true); } catch { MessageBox.Show("Cannot create object of type \"" + progID + "\""); } } if (acApp != null) { try { // By the time this is reached AutoCAD is fully // functional and can be interacted with through code acApp.Visible = true; ActivCAD.ActivCAD.IActivCAD app = (ActivCAD.ActivCAD.IActivCAD)acApp.GetInterfaceObject("ActivCAD.Commands"); if (app != null) { //---------------------------------------- On dessine le repère -------------------------------------------------- //---------------------------------------------------------------------------------------------------------------- Draw_Repere(app); //---------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------- //New_Calc(); //---------------------------------------- On dessine les observations ------------------------------------------- //---------------------------------------------------------------------------------------------------------------- Draw_Observations(app); //---------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------- // Let's generate the arguments to pass in: // an integer and a double //x1 / y1 / x2 / y2 / epaisseur / R / G / B / linetype / linefile //Observations //object[] args_poly1 = { 12, 34, 22, 43, 2, 255, 255, 0, "legende", "Continuous", Properties.Settings.Default.LignePath }; //object[] args_poly2 = { 37, 19, 42, 50, 1, 55, 255, 0, "legende", "Continuous", Properties.Settings.Default.LignePath }; //object[] args_poly3 = { 136, 70, 166, 52, 1, 55, 205, 0, "legende", "Continuous", Properties.Settings.Default.LignePath }; //Hachures //object[] args_surf1 = { 69, 78, 47, 65, 120, 0.6, 252, 125, 252, "legende", "NET3", Properties.Settings.Default.HachurePath }; // Now let's call our method dynamically //object res = app.GetType().InvokeMember("Init_Autocad_Environment", BindingFlags.InvokeMethod, null, app, null); //res = app.GetType().InvokeMember("AjoutePolyline", BindingFlags.InvokeMethod, null, app, args_poly1); //res = app.GetType().InvokeMember("AjoutePolyline", BindingFlags.InvokeMethod, null, app, args_poly2); //res = app.GetType().InvokeMember("AjoutePolyline", BindingFlags.InvokeMethod, null, app, args_poly3); //res = app.GetType().InvokeMember("AjouteSurface", BindingFlags.InvokeMethod, null, app, args_surf1); //app.GetType().InvokeMember("MyPoly", BindingFlags.InvokeMethod, null, app, null); acApp.ZoomExtents(); //MessageBox.Show("AddNumbers returned: " + res.ToString()); } } catch (System.Exception ex) { MessageBox.Show("Problem executing component: " + ex.Message); } } }