/// <summary> /// plotting method /// </summary> /// <param name="pdfFileName"> name</param> /// <param name="printModel">print param model</param> public static void PlotCurrentLayout(string pdfFileName, PrintModel printModel) { // Get the current document and database, and start a transaction Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; //short bgPlot = (short)Application.GetSystemVariable("BACKGROUNDPLOT"); Application.SetSystemVariable("BACKGROUNDPLOT", 0); try { using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Reference the Layout Manager LayoutManager acLayoutMgr; acLayoutMgr = LayoutManager.Current; // Get the current layout and output its name in the Command Line window Layout acLayout; acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForRead) as Layout; // Get the PlotInfo from the layout PlotInfo acPlInfo = new PlotInfo(); acPlInfo.Layout = acLayout.ObjectId; // Get a copy of the PlotSettings from the layout PlotSettings acPlSet = new PlotSettings(acLayout.ModelType); acPlSet.CopyFrom(acLayout); // Update the PlotSettings object PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current; var sheetList = acPlSetVdr.GetPlotStyleSheetList(); //acPlSetVdr.SetCurrentStyleSheet(acPlSet, "monochrome.ctb"); Extents2d points = new Extents2d(printModel.BlockPosition, printModel.BlockDimensions); bool isHor = printModel.IsFormatHorizontal(); //pdfCreator.GetBlockDimensions(); string canonName = printModel.GetCanonNameByWidthAndHeight(); //acDoc.Utility.TranslateCoordinates(point1, acWorld, acDisplayDCS, False); acPlSetVdr.SetPlotWindowArea(acPlSet, points); acPlSetVdr.SetPlotType(acPlSet, Db.PlotType.Window); if (!isHor) { acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees090); } //else if(canonName =="ISO_full_bleed_A4_(297.00_x_210.00_MM)") // acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees090); else { acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees000); } // Set the plot scale acPlSetVdr.SetUseStandardScale(acPlSet, false); acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit); // Center the plot acPlSetVdr.SetPlotCentered(acPlSet, true); //acPlSetVdr.SetClosestMediaName(acPlSet,printModel.width,printModel.height,PlotPaperUnit.Millimeters,true); //string curCanonName = PdfCreator.GetLocalNameByAtrrValue(formatValue); acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG_To_PDF_Uzle.pc3", canonName); //acPlSetVdr.SetCanonicalMediaName(acPlSet, curCanonName); // Set the plot device to use // Set the plot info as an override since it will // not be saved back to the layout acPlInfo.OverrideSettings = acPlSet; // Validate the plot info PlotInfoValidator acPlInfoVdr = new PlotInfoValidator(); acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled; acPlInfoVdr.Validate(acPlInfo); // Check to see if a plot is already in progress if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting) { using (PlotEngine acPlEng = PlotFactory.CreatePublishEngine()) { // Track the plot progress with a Progress dialog PlotProgressDialog acPlProgDlg = new PlotProgressDialog(false, 1, true); using (acPlProgDlg) { // Define the status messages to display when plotting starts acPlProgDlg.set_PlotMsgString(PlotMessageIndex.DialogTitle, "Plot Progress"); acPlProgDlg.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Cancel Job"); acPlProgDlg.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "Cancel Sheet"); acPlProgDlg.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, "Sheet Set Progress"); acPlProgDlg.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "Sheet Progress"); // Set the plot progress range acPlProgDlg.LowerPlotProgressRange = 0; acPlProgDlg.UpperPlotProgressRange = 100; acPlProgDlg.PlotProgressPos = 0; // Display the Progress dialog acPlProgDlg.OnBeginPlot(); acPlProgDlg.IsVisible = true; // Start to plot the layout acPlEng.BeginPlot(acPlProgDlg, null); // Define the plot output string filename = Path.Combine(Path.GetDirectoryName(acDoc.Name), pdfFileName); Active.Editor.WriteMessage(filename); acPlEng.BeginDocument(acPlInfo, acDoc.Name, null, 1, true, filename); // Display information about the current plot acPlProgDlg.set_PlotMsgString(PlotMessageIndex.Status, "Plotting: " + acDoc.Name + " - " + acLayout.LayoutName); // Set the sheet progress range acPlProgDlg.OnBeginSheet(); acPlProgDlg.LowerSheetProgressRange = 0; acPlProgDlg.UpperSheetProgressRange = 100; acPlProgDlg.SheetProgressPos = 0; // Plot the first sheet/layout PlotPageInfo acPlPageInfo = new PlotPageInfo(); acPlEng.BeginPage(acPlPageInfo, acPlInfo, true, null); acPlEng.BeginGenerateGraphics(null); acPlEng.EndGenerateGraphics(null); // Finish plotting the sheet/layout acPlEng.EndPage(null); acPlProgDlg.SheetProgressPos = 100; acPlProgDlg.OnEndSheet(); // Finish plotting the document acPlEng.EndDocument(null); // Finish the plot acPlProgDlg.PlotProgressPos = 100; acPlProgDlg.OnEndPlot(); acPlEng.EndPlot(null); } } } } } catch (Exception e) { Application.ShowAlertDialog(e.Message); } }