private void PublisherDSD(DsdEntryCollection collection) { var dsdFile = Path.Combine(dir, filePdfOutputName + ".dsd"); var destFile = Path.Combine(dir, filePdfOutputName + ".pdf"); Application.SetSystemVariable("BACKGROUNDPLOT", 0); using (var dsd = new DsdData()) { dsd.SetDsdEntryCollection(collection); dsd.SheetType = SheetType.MultiPdf; dsd.IsSheetSet = true; dsd.NoOfCopies = 1; dsd.IsHomogeneous = false; dsd.DestinationName = destFile; dsd.SheetSetName = "PublisherSet"; dsd.PromptForDwfName = false; PostProcessDSD(dsd, dsdFile); } using (var progressDlg = new PlotProgressDialog(false, collection.Count, true)) { progressDlg.IsVisible = true; var publisher = Application.Publisher; PlotConfigManager.SetCurrentConfig("clk-PDF.pc3"); publisher.PublishDsd(dsdFile, progressDlg); progressDlg.Destroy(); } }
// Plot the layouts public void Publish() { if (TryCreateDSD()) { var bgp = Application.GetSystemVariable("BACKGROUNDPLOT"); var ctab = Application.GetSystemVariable("CTAB"); try { Application.SetSystemVariable("BACKGROUNDPLOT", 0); var publisher = Application.Publisher; var plotDlg = new PlotProgressDialog(false, sheetNum, false); publisher.PublishDsd(dsdFile, plotDlg); plotDlg.Destroy(); } catch (Exception exn) { var ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("\nError: {0}\n{1}", exn.Message, exn.StackTrace); throw; } finally { Application.SetSystemVariable("BACKGROUNDPLOT", bgp); Application.SetSystemVariable("CTAB", ctab); File.Delete(dsdFile); } } }
// Plot the layouts public void Publish(string layerName) { if (TryCreateDSD(layerName)) { object bgp = Application.GetSystemVariable("BACKGROUNDPLOT"); object ctab = Application.GetSystemVariable("CTAB"); try { Application.SetSystemVariable("BACKGROUNDPLOT", 0); Publisher publisher = Application.Publisher; PlotProgressDialog plotDlg = new PlotProgressDialog(false, this.sheetNum, true); publisher.PublishDsd(this.dsdFile, plotDlg); plotDlg.Destroy(); File.Delete(this.dsdFile); } catch (System.Exception exn) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("\nError: {0}\n{1}", exn.Message, exn.StackTrace); throw; } finally { Application.SetSystemVariable("BACKGROUNDPLOT", bgp); Application.SetSystemVariable("CTAB", ctab); } } }
public void Publish() { if (TryCreateDSD()) { Publisher publisher = AcAp.Publisher; PlotProgressDialog plotDlg = new PlotProgressDialog(false, this.sheetNum, true); publisher.PublishDsd(this.dsdFile, plotDlg); plotDlg.Destroy(); File.Delete(this.dsdFile); } }
public void Publish() { if (TryCreateDSD()) { Publisher publisher = Acad.Publisher; PlotProgressDialog plotDlg = new PlotProgressDialog(false, sheetNum, true) { IsVisible = false }; publisher.PublishDsd(dsdFile, plotDlg); plotDlg.Destroy(); File.Delete(dsdFile); } }
public void Publish() { if (TryCreateDSD()) { //Publisher publisher = Autodesk.AutoCAD.ApplicationServices.ApplicationServices.Application.Publisher; Publisher publisher = Autodesk.AutoCAD.ApplicationServices.Core.Application.Publisher; //publisher.PublishExecute(); --for printing with plotconfigs // Attach necessary event handlers //publisher.BeginPublishingSheet += new BeginPublishingSheetEventHandler(HandleBeginPublishingSheet); //publisher.EndPublish += new EndPublishEventHandler(HandleEndPublish); //publisher.CancelledOrFailedPublishing += new CancelledOrFailedPublishingEventHandler(HandleCancelledOrFailedPublish); PlotProgressDialog plotDlg = new PlotProgressDialog(false, this._numberOfsheets, true); //File.WriteAllText("D:\\sheets.txt", this.sheetNum.ToString()); //test publisher.PublishDsd(this._dsdFile, plotDlg); plotDlg.Destroy(); File.Delete(this._dsdFile); } }
// Plot the layouts public void Publish() { if (tryCreateDSD()) { object bgp = Application.GetSystemVariable("BACKGROUNDPLOT"); object ctab = Application.GetSystemVariable("CTAB"); try { Application.SetSystemVariable("BACKGROUNDPLOT", 0); Publisher publisher = Application.Publisher; PlotProgressDialog plotDlg = new PlotProgressDialog(false, this.sheetNum, false); publisher.PublishDsd(this.dsdFile, plotDlg); plotDlg.Destroy(); } catch (System.Exception exn) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("\nError: {0}\n{1}", exn.Message, exn.StackTrace); throw; } finally { Application.SetSystemVariable("BACKGROUNDPLOT", bgp); Application.SetSystemVariable("CTAB", ctab); File.Delete(this.dsdFile); } } }
public void PublisherDSD(DsdEntryCollection collection) { try { var dsdFile = Path.Combine(dir, filePdfOutputName + ".dsd"); if (!filePdfOutputName.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase)) { filePdfOutputName += ".pdf"; } var destFile = Path.Combine(dir, filePdfOutputName); CheckFileAccess(destFile); Application.SetSystemVariable("BACKGROUNDPLOT", 0); using (var dsd = new DsdData()) { if (PikSettings.UserGroup == "ДО") { dsd.PlotStampOn = true; dsd.ProjectPath = dir; } dsd.SetDsdEntryCollection(collection); dsd.LogFilePath = Path.Combine(dir, "logPlotPdf.log"); dsd.SheetType = SheetType.MultiPdf; dsd.IsSheetSet = true; dsd.NoOfCopies = 1; dsd.IsHomogeneous = false; dsd.DestinationName = destFile; dsd.SheetSetName = "PublisherSet"; dsd.PromptForDwfName = false; PostProcessDSD(dsd, dsdFile); } var nbSheets = collection.Count; using (var progressDlg = new PlotProgressDialog(false, nbSheets, true)) { progressDlg.set_PlotMsgString(PlotMessageIndex.DialogTitle, title); progressDlg.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Отмена задания"); progressDlg.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "Отмена листа"); progressDlg.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, title); progressDlg.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "Печать листа"); progressDlg.UpperPlotProgressRange = 100; progressDlg.LowerPlotProgressRange = 0; progressDlg.UpperSheetProgressRange = 100; progressDlg.LowerSheetProgressRange = 0; progressDlg.IsVisible = true; var publisher = Application.Publisher; PlotConfigManager.SetCurrentConfig("clk-PDF.pc3"); publisher.PublishDsd(dsdFile, progressDlg); progressDlg.Destroy(); } NetLib.IO.Path.TryDeleteFile(dsdFile); // Добавить бланк if (Options.BlankOn) { var tempPdf = NetLib.IO.Path.GetTempFile(".pdf"); try { var blank = IO.Path.GetLocalSettingsFile(@"Support\blank.pdf"); new PdfEditor().AddSheet(filePdfOutputName, blank, 1, Options.BlankPageNumber, tempPdf); while (true) { try { File.Copy(tempPdf, filePdfOutputName, true); Process.Start(filePdfOutputName); break; } catch { var res = MessageBox.Show($"Закройте pdf файл - {filePdfOutputName}", "Ошибка добавление бланка", MessageBoxButtons.OKCancel); if (res != DialogResult.OK) { break; } } } } finally { NetLib.IO.Path.TryDeleteFile(tempPdf); } } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { MessageBox.Show(ex.Message); } }
public void PrintTT() { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; List <String> imagelist = new List <String>(); string directory = @"D:\";//磁盘路径 string MediaName = comboBoxMedia.SelectedItem.ToString().Replace(" ", "_").Replace("毫米", "MM").Replace("英寸", "Inches").Replace("像素", "Pixels"); try { if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting) { using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { int flag = 0; //获取当前布局管理器变量 LayoutManager acLayoutMgr = LayoutManager.Current; //获取当前布局变量 Layout acLayout = (Layout)acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForRead); //Layout acLayout = (Layout)acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForWrite); //获取当前布局的打印信息 PlotInfo acPlInfo = new PlotInfo() { Layout = acLayout.ObjectId }; //提示用户输入打印窗口的两个角点 PromptPointResult resultp = ed.GetPoint("\n指定第一个角点"); if (resultp.Status != PromptStatus.OK) { return; } Point3d basePt = resultp.Value; resultp = ed.GetCorner("指定对角点", basePt); if (resultp.Status != PromptStatus.OK) { return; } Point3d cornerPt = resultp.Value; //选择实体对象 // PromptSelectionOptions result1 = new PromptSelectionOptions(); SelectionFilter frameFilter = new SelectionFilter( new TypedValue[] { new TypedValue(0, "LWPOLYLINE"), new TypedValue(90, 4), new TypedValue(70, 1) }); PromptSelectionResult selectedFrameResult = ed.SelectWindow(basePt, cornerPt, frameFilter); // PromptSelectionResult selectedFrameResult = ed.GetSelection(result1, frameFilter); PromptSelectionResult selectedFrameResult1 = ed.SelectAll(frameFilter); if (selectedFrameResult.Status == PromptStatus.OK) { List <ObjectId> selectedObjectIds = new List <ObjectId>(selectedFrameResult.Value.GetObjectIds()); List <ObjectId> resultObjectIds = new List <ObjectId>(selectedFrameResult.Value.GetObjectIds()); RemoveInnerPLine(acTrans, ref selectedObjectIds, ref resultObjectIds); foreach (ObjectId frameId in resultObjectIds) { Polyline framePline = acTrans.GetObject(frameId, OpenMode.ForRead) as Polyline; framePline.Highlight(); } PlotSettings acPlSet = new PlotSettings(acLayout.ModelType); acPlSet.CopyFrom(acLayout); //着色打印选项,设置按线框进行打印 acPlSet.ShadePlot = PlotSettingsShadePlotType.Wireframe; PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current; //打印比例 //用户标准打印 acPlSetVdr.SetUseStandardScale(acPlSet, true); acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit); //居中打印 acPlSetVdr.SetPlotCentered(acPlSet, true); //调用GetPlotStyleSheetList之后才可以使用SetCurrentStyleSheet System.Collections.Specialized.StringCollection sc = acPlSetVdr.GetPlotStyleSheetList(); //设置打印样式表 if (comboBoxStyleSheet.SelectedItem.ToString() == "无") { acPlSetVdr.SetCurrentStyleSheet(acPlSet, "acad.ctb"); } else { acPlSetVdr.SetCurrentStyleSheet(acPlSet, comboBoxStyleSheet.SelectedItem.ToString()); } //选择方向 if (radioButtonHorizontal.Checked) { //横向 acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", MediaName); acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees090); } //竖向 if (radioButtonVertical.Checked) { acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", MediaName);//获取打印图纸尺寸ComboxMedia acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees000); } PlotProgressDialog acPlProgDlg = new PlotProgressDialog(false, resultObjectIds.Count, true); string imagename = ""; string[] files = new string[] { }; List <string> listfile = new List <string>(); foreach (var frame in resultObjectIds) { if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } flag++; Entity ent = acTrans.GetObject(frame, OpenMode.ForRead) as Entity; imagename = string.Format("{0}-{1}.pdf", frame, flag); //imagelist.Add(directory + imagename); listfile.Add(directory + imagename); //设置是否使用打印样式 acPlSet.ShowPlotStyles = true; //设置打印区域 Extents3d extents3d = ent.GeometricExtents; Extents2d E2d = new Extents2d(extents3d.MinPoint.X, extents3d.MinPoint.Y, extents3d.MaxPoint.X, extents3d.MaxPoint.Y); acPlSetVdr.SetPlotWindowArea(acPlSet, E2d); acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Window); //重载和保存打印信息 acPlInfo.OverrideSettings = acPlSet; //验证打印信息设置,看是否有误 PlotInfoValidator acPlInfoVdr = new PlotInfoValidator(); acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled; acPlInfoVdr.Validate(acPlInfo); while (PlotFactory.ProcessPlotState != ProcessPlotState.NotPlotting) { continue; } #region BackUpCode //保存App的原参数 short bgPlot = (short)Application.GetSystemVariable("BACKGROUNDPLOT"); //设定为前台打印,加快打印速度 Application.SetSystemVariable("BACKGROUNDPLOT", 0); PlotEngine acPlEng1 = PlotFactory.CreatePublishEngine(); // acPlProgDlg.set_PlotMsgString(PlotMessageIndex.DialogTitle, "图片输出"); // acPlProgDlg.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "取消输出"); //acPlProgDlg.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "输出进度"); acPlProgDlg.LowerPlotProgressRange = 0; acPlProgDlg.UpperPlotProgressRange = 100; acPlProgDlg.PlotProgressPos = 0; acPlProgDlg.OnBeginPlot(); acPlProgDlg.IsVisible = true; acPlEng1.BeginPlot(acPlProgDlg, null); acPlEng1.BeginDocument(acPlInfo, "", null, 1, true, directory + imagename); // acPlProgDlg.set_PlotMsgString(PlotMessageIndex.Status, string.Format("正在输出文件")); acPlProgDlg.OnBeginSheet(); acPlProgDlg.LowerSheetProgressRange = 0; acPlProgDlg.UpperSheetProgressRange = 100; acPlProgDlg.SheetProgressPos = 0; PlotPageInfo acPlPageInfo = new PlotPageInfo(); acPlEng1.BeginPage(acPlPageInfo, acPlInfo, true, null); acPlEng1.BeginGenerateGraphics(null); acPlEng1.EndGenerateGraphics(null); acPlEng1.EndPage(null); acPlProgDlg.SheetProgressPos = 100; acPlProgDlg.OnEndSheet(); acPlEng1.EndDocument(null); acPlProgDlg.PlotProgressPos = 100; acPlProgDlg.OnEndPlot(); acPlEng1.EndPlot(null); acPlEng1.Dispose(); acPlEng1.Destroy(); Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot); #endregion } files = listfile.ToArray(); PlotConfig config = PlotConfigManager.CurrentConfig; //获取去除扩展名后的文件名(不含路径) string fileName = SymbolUtilityServices.GetSymbolNameFromPathName(acDoc.Name, "dwg"); //定义保存文件对话框 PromptSaveFileOptions opt = new PromptSaveFileOptions("文件名") { //保存文件对话框的文件扩展名列表 Filter = "*" + config.DefaultFileExtension + "|*" + config.DefaultFileExtension, DialogCaption = "浏览打印文件", //保存文件对话框的标题 InitialDirectory = @"D:\", //缺省保存目录 InitialFileName = fileName + "-" + acLayout.LayoutName //缺省保存文件名 }; //根据保存对话框中用户的选择,获取保存文件名 PromptFileNameResult result = ed.GetFileNameForSave(opt); if (result.Status != PromptStatus.OK) { return; } fileName = result.StringResult; //string fileName = @"D:\输出.pdf"; PdfDocumentBase docx = PdfDocument.MergeFiles(files); docx.Save(fileName, FileFormat.PDF); System.Diagnostics.Process.Start(fileName); //保存App的原参数 short bgPlot1 = (short)Application.GetSystemVariable("BACKGROUNDPLOT"); //设定为前台打印,加快打印速度 Application.SetSystemVariable("BACKGROUNDPLOT", 0); PlotEngine acPlEng = PlotFactory.CreatePublishEngine(); acPlProgDlg.set_PlotMsgString(PlotMessageIndex.DialogTitle, "图片输出"); acPlProgDlg.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "取消输出"); acPlProgDlg.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "输出进度"); acPlProgDlg.LowerPlotProgressRange = 0; acPlProgDlg.UpperPlotProgressRange = 100; acPlProgDlg.PlotProgressPos = 0; acPlProgDlg.OnBeginPlot(); acPlProgDlg.IsVisible = true; acPlEng.BeginPlot(acPlProgDlg, null); acPlEng.BeginDocument(acPlInfo, "", null, 1, true, directory + imagename); acPlProgDlg.set_PlotMsgString(PlotMessageIndex.Status, string.Format("正在输出文件")); acPlProgDlg.OnBeginSheet(); acPlProgDlg.LowerSheetProgressRange = 0; acPlProgDlg.UpperSheetProgressRange = 100; acPlProgDlg.SheetProgressPos = 0; PlotPageInfo acPlPageInfo1 = new PlotPageInfo(); acPlEng.BeginPage(acPlPageInfo1, acPlInfo, true, null); acPlEng.BeginGenerateGraphics(null); acPlEng.EndGenerateGraphics(null); acPlEng.EndPage(null); acPlProgDlg.SheetProgressPos = 100; acPlProgDlg.OnEndSheet(); acPlEng.EndDocument(null); acPlProgDlg.PlotProgressPos = 100; acPlProgDlg.OnEndPlot(); acPlEng.EndPlot(null); acPlEng.Dispose(); acPlEng.Destroy(); Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot1); acPlProgDlg.Dispose(); acPlProgDlg.Destroy(); for (int i = 0; i < files.Length; i++) { File.Delete(files[i]); } } while (PlotFactory.ProcessPlotState != ProcessPlotState.NotPlotting) { continue; } //MessageBox.Show("打印完成!"); } } else { ed.WriteMessage("\n另一个打印进程正在进行中."); } } catch (System.Exception) { throw; } }