/// <summary> /// Plot with override configuration /// </summary> /// <param name="acApp">AutoCAD application</param> /// <param name="plotConfig">Plot override Configuration</param> public void Plot(AcadApplication acApp, EPlotConfig pConfig) { AcadDocuments acDocs = acApp.Documents; int opFlag = DocIndex(acDocs); if (Open(acApp)) { AcadLayout acLot = acApp.ActiveDocument.ActiveLayout; // Store plot configuration of active layout double numerator, denominator; EPlotConfig strConfig = new EPlotConfig( acLot.ConfigName, acLot.CanonicalMediaName, acLot.StyleSheet, acLot.PlotType, acLot.StandardScale, acLot.UseStandardScale, 1, acLot.CenterPlot, acLot.PlotRotation, false, acLot.ScaleLineweights);//, acLot.PlotOrigin); acLot.GetCustomScale(out numerator, out denominator); try { // Setting layout for plot acLot.ConfigName = pConfig.Plotter; acLot.CanonicalMediaName = pConfig.CanonicalMediaName; acLot.StyleSheet = pConfig.PlotStyleTable; acLot.PlotType = pConfig.PlotType; acLot.StandardScale = pConfig.StandardScale; acLot.UseStandardScale = pConfig.UseStandardScale; // NOTE: ----------------------------------------------------- // ROTATION AUTOMATICALLY FEATURE WILL BE WRITTEN IN NEXT TIME // ----------------------------------------------------------- acLot.PlotRotation = pConfig.PlotRotation; acLot.ScaleLineweights = pConfig.IsScaleLineweight; //acLot.PlotOrigin = pConfig.PlotOrigin; acLot.SetCustomScale(pConfig.CustomScale, 1); // Update plot config then Plot acLot.RefreshPlotDeviceInfo(); acApp.ActiveDocument.Plot.PlotToDevice(); } catch { } // Restore layout setting of plot acLot.ConfigName = strConfig.Plotter; acLot.CanonicalMediaName = strConfig.CanonicalMediaName; acLot.StyleSheet = strConfig.PlotStyleTable; acLot.PlotType = strConfig.PlotType; acLot.StandardScale = strConfig.StandardScale; acLot.UseStandardScale = strConfig.UseStandardScale; acLot.PlotRotation = strConfig.PlotRotation; acLot.ScaleLineweights = strConfig.IsScaleLineweight; //acLot.PlotOrigin = strConfig.PlotOrigin; acLot.SetCustomScale(numerator, denominator); } // If sheet is not opened initially, closing this after plot finish if (opFlag == -1 && DocIndex(acDocs) != -1) { acDocs.Item(DocIndex(acDocs)).Close(false); } }
/// <summary> /// Opening sheet on acad application /// </summary> /// <param name="acApp"></param> internal bool Open(AcadApplication acApp) { try { AcadDocuments acDocs = acApp.Documents; int id = DocIndex(acDocs); if (id != -1) { // If file is not opened, switch to it acDocs.Item(id).Activate(); } else { // If file is not opened, opening it in read-only acDocs.Open(Path, true); } // Switch to layout AcadLayouts acLots = acApp.ActiveDocument.Layouts; foreach (AcadLayout acLot in acLots) { if (acLot.Name == this.Name) { acApp.ActiveDocument.ActiveLayout = acLot; break; } } return(true); } catch { return(false); } }
/// <summary> /// Check whether file of sheet is opened /// If file is opened, return index of document (!= -1) /// </summary> /// /// <param name="acDocs">Acad Documents collection</param> private int DocIndex(AcadDocuments acDocs) { int opFlag = -1; for (int i = 0; i < acDocs.Count; i++) { AcadDocument acDoc = acDocs.Item(i); if (acDoc.FullName == Path) { opFlag = i; return(opFlag); } } return(opFlag); }
/// <summary> /// Perform plot with current AutoCAD application & current sheet /// </summary> public void Plot(AcadApplication acApp) { AcadDocuments acDocs = acApp.Documents; int opFlag = DocIndex(acDocs); try { if (Open(acApp)) { AcadPlot acPlotObject = acApp.ActiveDocument.Plot; // Plot with layout configuration acPlotObject.PlotToDevice(); } } catch { } // If sheet is not opened initially, closing this after plot finish if (opFlag == -1 && DocIndex(acDocs) != -1) { acDocs.Item(DocIndex(acDocs)).Close(false); } }