| Правила | Регистрация | Пользователи | Поиск | Сообщения за день | Все разделы прочитаны |  Справка по форуму | Файлообменник |

Вернуться   Форум DWG.RU > Программное обеспечение > Программирование > .NET > Autocad2020. Программно долго печатает один чертеж pe.EndPlot(null);

Autocad2020. Программно долго печатает один чертеж pe.EndPlot(null);

Ответ
Поиск в этой теме
Непрочитано 30.04.2021, 11:50 #1
Autocad2020. Программно долго печатает один чертеж pe.EndPlot(null);
veb86
 
Проектировщик электрических сетей
 
Пенза
Регистрация: 17.01.2014
Сообщений: 176

Всем добрый день! И всех с наступающими праздниками!
Часто приходится PDFить, решил сделать под себя модуль который будет печатать автоматически. Как и планировал код будет выложен на ГИТХАб и я на него ссылку дам. Сейчас причесываю, он печатает и вроде бы все хорошо. НО, один лист печатается 2,5 минуты. Это просто жесть. Я вообще не представляю почему и отчего такая долгая печать.

Эта команда ppd.OnEndPlot(); выполняется 2,5 минуты. При чем если ручками печатать то печатается все очень быстро. Пробовал печатать разными принтерами: PDFCreator, Microsoft Printer to PDF, DWG to PDF.pc3. результаты плюс/минус одинаковые.
Печать была основана на коде которые приведен ниже, со ссылками на автора. Конечно с некоторыми доработками. Код представленный ниже так же печатается долго и все так же ppd.OnEndPlot();.
Подскажите в чем может быть проблема?

Код:
[Выделить все]
     // ============================================================================
    // PlotRegionToPDF.cs
    // © Andrey Bushman, 2014
    // ============================================================================
    // The PLOTREGION command plot a Region object to PDF.
    // ============================================================================
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
     
    using cad = Autodesk.AutoCAD.ApplicationServices.Application;
    using Ap = Autodesk.AutoCAD.ApplicationServices;
    using Db = Autodesk.AutoCAD.DatabaseServices;
    using Ed = Autodesk.AutoCAD.EditorInput;
    using Rt = Autodesk.AutoCAD.Runtime;
    using Gm = Autodesk.AutoCAD.Geometry;
    using Wn = Autodesk.AutoCAD.Windows;
    using Hs = Autodesk.AutoCAD.DatabaseServices.HostApplicationServices;
    using Us = Autodesk.AutoCAD.DatabaseServices.SymbolUtilityServices;
    using Br = Autodesk.AutoCAD.BoundaryRepresentation;
    using Pt = Autodesk.AutoCAD.PlottingServices;
     
    [assembly: Rt.CommandClass(typeof(Bushman.CAD.ProblemSamples.PlotRegionToPDF))]
     
    namespace Bushman.CAD.ProblemSamples {
     
      public static class PlotRegionToPDF {
    #if AUTOCAD_NEWER_THAN_2012
        const String acedTransOwner = "accore.dll";
    #else
        const String acedTransOwner = "acad.exe";    
    #endif
     
    #if AUTOCAD_NEWER_THAN_2014
        const String acedTrans_x86_Prefix = "_";
    #else
        const String acedTrans_x86_Prefix = "";
    #endif
     
        const String acedTransName = "acedTrans";
     
        [DllImport(acedTransOwner, CallingConvention = CallingConvention.Cdecl,
                EntryPoint = acedTrans_x86_Prefix + acedTransName)]
        static extern Int32 acedTrans_x86(Double[] point, IntPtr fromRb, 
          IntPtr toRb, Int32 disp, Double[] result);
     
        [DllImport(acedTransOwner, CallingConvention = CallingConvention.Cdecl,
                EntryPoint = acedTransName)]
        static extern Int32 acedTrans_x64(Double[] point, IntPtr fromRb, 
          IntPtr toRb, Int32 disp, Double[] result);
     
        public static Int32 acedTrans(Double[] point, IntPtr fromRb, IntPtr toRb,
          Int32 disp, Double[] result) {
            if(IntPtr.Size == 4)
              return acedTrans_x86(point, fromRb, toRb, disp, result);
            else
              return acedTrans_x64(point, fromRb, toRb, disp, result);
        }
     
        [Rt.CommandMethod("plotRegion", Rt.CommandFlags.Modal)]
        public static void PlotRegion() {
          Ap.Document doc = cad.DocumentManager.MdiActiveDocument;
          if(doc == null || doc.IsDisposed)
            return;
     
          Ed.Editor ed = doc.Editor;
          Db.Database db = doc.Database;
     
          using(doc.LockDocument()) {
            Ed.PromptEntityOptions peo = new Ed.PromptEntityOptions(
             "\nSelect a region"
             );
     
            peo.SetRejectMessage("\nIt is not a region."
              );
            peo.AddAllowedClass(typeof(Db.Region), false);
     
            Ed.PromptEntityResult per = ed.GetEntity(peo);
     
            if(per.Status != Ed.PromptStatus.OK) {
              ed.WriteMessage("\nCommand canceled.\n");
              return;
            }
     
            Db.ObjectId regionId = per.ObjectId;
     
            Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32
              .SaveFileDialog();
            saveFileDialog.Title =
              "PDF file name";
            saveFileDialog.Filter = "PDF-files|*.pdf";
            bool? result = saveFileDialog.ShowDialog();
     
            if(!result.HasValue || !result.Value) {
              ed.WriteMessage("\nCommand canceled.");
              return;
            }
     
            String pdfFileName = saveFileDialog.FileName;
     
            PlotRegion(regionId, "DWG To PDF.pc3",
              "ISO_A4_(210.00_x_297.00_MM)", pdfFileName);
     
            ed.WriteMessage("\nThe \"{0}\" file created.\n", pdfFileName);
          }
        }
     
        // This method helps to get correct "boundary box" for the regions which 
        // created through the splines. Written by Alexander Rivilis.
        public static void GetVisualBoundary(this Db.Region region, double delta,
            ref Gm.Point2d minPoint, ref Gm.Point2d maxPoint) {
          using(Gm.BoundBlock3d boundBlk = new Gm.BoundBlock3d()) {
            using(Br.Brep brep = new Br.Brep(region)) {
              foreach(Br.Edge edge in brep.Edges) {
                using(Gm.Curve3d curve = edge.Curve) {
                  Gm.ExternalCurve3d curve3d = curve as Gm.ExternalCurve3d;
     
                  if(curve3d != null && curve3d.IsNurbCurve) {
                    using(Gm.NurbCurve3d nurbCurve = curve3d.NativeCurve
                      as Gm.NurbCurve3d) {
                      Gm.Interval interval = nurbCurve.GetInterval();
                      for(double par = interval.LowerBound; par <=
                        interval.UpperBound; par += (delta * 2.0)) {
                        Gm.Point3d p = nurbCurve.EvaluatePoint(par);
                        if(!boundBlk.IsBox)
                          boundBlk.Set(p, p);
                        else
                          boundBlk.Extend(p);
                      }
                    }
                  }
                  else {
                    if(!boundBlk.IsBox) {
                      boundBlk.Set(edge.BoundBlock.GetMinimumPoint(),
                        edge.BoundBlock.GetMaximumPoint());
                    }
                    else {
                      boundBlk.Extend(edge.BoundBlock.GetMinimumPoint());
                      boundBlk.Extend(edge.BoundBlock.GetMaximumPoint());
                    }
                  }
                }
              }
            }
            boundBlk.Swell(delta);
     
            minPoint = new Gm.Point2d(boundBlk.GetMinimumPoint().X,
              boundBlk.GetMinimumPoint().Y);
            maxPoint = new Gm.Point2d(boundBlk.GetMaximumPoint().X,
              boundBlk.GetMaximumPoint().Y);
          }
        }
     
        // This code based on Kean Walmsley's article:
        // http://through-the-interface.typepad.com/through_the_interface/2007/10/plotting-a-wind.html
        public static void PlotRegion(Db.ObjectId regionId, String pcsFileName,
      String mediaName, String outputFileName) {
     
          if(regionId.IsNull)
            throw new ArgumentException("regionId.IsNull == true");
          if(!regionId.IsValid)
            throw new ArgumentException("regionId.IsValid == false");
     
          if(regionId.ObjectClass.Name != "AcDbRegion")
            throw new ArgumentException("regionId.ObjectClass.Name != AcDbRegion");
     
          if(pcsFileName == null)
            throw new ArgumentNullException("pcsFileName");
          if(pcsFileName.Trim() == String.Empty)
            throw new ArgumentException("pcsFileName.Trim() == String.Empty");
     
          if(mediaName == null)
            throw new ArgumentNullException("mediaName");
          if(mediaName.Trim() == String.Empty)
            throw new ArgumentException("mediaName.Trim() == String.Empty");
     
          if(outputFileName == null)
            throw new ArgumentNullException("outputFileName");
          if(outputFileName.Trim() == String.Empty)
            throw new ArgumentException("outputFileName.Trim() == String.Empty");
     
          Db.Database previewDb = Hs.WorkingDatabase;
          Db.Database db = null;
          Ap.Document doc = cad.DocumentManager.MdiActiveDocument;
          if(doc == null || doc.IsDisposed)
            return;
     
          Ed.Editor ed = doc.Editor;
          try {
            if(regionId.Database != null && !regionId.Database.IsDisposed) {
              Hs.WorkingDatabase = regionId.Database;
              db = regionId.Database;
            }
            else {
              db = doc.Database;
            }
     
            using(doc.LockDocument()) {
              using(Db.Transaction tr = db.TransactionManager.StartTransaction()) {
                Db.Region region = tr.GetObject(regionId,
                Db.OpenMode.ForRead) as Db.Region;
     
                Db.Extents3d extends = region.GeometricExtents;
                Db.ObjectId modelId = Us.GetBlockModelSpaceId(db);
                Db.BlockTableRecord model = tr.GetObject(modelId,
                Db.OpenMode.ForRead) as Db.BlockTableRecord;
     
                Db.Layout layout = tr.GetObject(model.LayoutId,
                Db.OpenMode.ForRead) as Db.Layout;
     
                using(Pt.PlotInfo pi = new Pt.PlotInfo()) {
                  pi.Layout = model.LayoutId;
     
                  using(Db.PlotSettings ps = new Db.PlotSettings(layout.ModelType)
                    ) {
     
                    ps.CopyFrom(layout);
     
                    Db.PlotSettingsValidator psv = Db.PlotSettingsValidator
                      .Current;
     
                    Gm.Point2d bottomLeft = Gm.Point2d.Origin;
                    Gm.Point2d topRight = Gm.Point2d.Origin;
     
                    region.GetVisualBoundary(0.1, ref bottomLeft,
                      ref topRight);
     
                    Gm.Point3d bottomLeft_3d = new Gm.Point3d(bottomLeft.X,
                      bottomLeft.Y, 0);
                    Gm.Point3d topRight_3d = new Gm.Point3d(topRight.X, topRight.Y,
                      0);
     
                    Db.ResultBuffer rbFrom = new Db.ResultBuffer(new Db.TypedValue(
                      5003, 0));
                    Db.ResultBuffer rbTo = new Db.ResultBuffer(new Db.TypedValue(
                      5003, 2));
     
                    double[] firres = new double[] { 0, 0, 0 };
                    double[] secres = new double[] { 0, 0, 0 };
     
                    acedTrans(bottomLeft_3d.ToArray(), rbFrom.UnmanagedObject,
                      rbTo.UnmanagedObject, 0, firres);
                    acedTrans(topRight_3d.ToArray(), rbFrom.UnmanagedObject,
                      rbTo.UnmanagedObject, 0, secres);
     
                    Db.Extents2d extents = new Db.Extents2d(
                        firres[0],
                        firres[1],
                        secres[0],
                        secres[1]
                      );
     
                    psv.SetZoomToPaperOnUpdate(ps, true);
     
                    psv.SetPlotWindowArea(ps, extents);
                    psv.SetPlotType(ps, Db.PlotType.Window);
                    psv.SetUseStandardScale(ps, true);
                    psv.SetStdScaleType(ps, Db.StdScaleType.ScaleToFit);
                    psv.SetPlotCentered(ps, true);
                    psv.SetPlotRotation(ps, Db.PlotRotation.Degrees000);
     
                    // We'll use the standard DWF PC3, as
                    // for today we're just plotting to file
                    psv.SetPlotConfigurationName(ps, pcsFileName, mediaName);
     
                    // We need to link the PlotInfo to the
                    // PlotSettings and then validate it
                    pi.OverrideSettings = ps;
                    Pt.PlotInfoValidator piv = new Pt.PlotInfoValidator();
                    piv.MediaMatchingPolicy = Pt.MatchingPolicy.MatchEnabled;
                    piv.Validate(pi);
     
                    // A PlotEngine does the actual plotting
                    // (can also create one for Preview)
                    if(Pt.PlotFactory.ProcessPlotState == Pt.ProcessPlotState
                      .NotPlotting) {
                      using(Pt.PlotEngine pe = Pt.PlotFactory.CreatePublishEngine()
                        ) {
                        // Create a Progress Dialog to provide info
                        // and allow thej user to cancel
     
                        using(Pt.PlotProgressDialog ppd =
                          new Pt.PlotProgressDialog(false, 1, true)) {
                          ppd.set_PlotMsgString(
                          Pt.PlotMessageIndex.DialogTitle, "Custom Plot Progress");
     
                          ppd.set_PlotMsgString(
                            Pt.PlotMessageIndex.CancelJobButtonMessage,
                            "Cancel Job");
     
                          ppd.set_PlotMsgString(
                          Pt.PlotMessageIndex.CancelSheetButtonMessage,
                          "Cancel Sheet");
     
                          ppd.set_PlotMsgString(
                          Pt.PlotMessageIndex.SheetSetProgressCaption,
                          "Sheet Set Progress");
     
                          ppd.set_PlotMsgString(
                            Pt.PlotMessageIndex.SheetProgressCaption,
                           "Sheet Progress");
     
                          ppd.LowerPlotProgressRange = 0;
                          ppd.UpperPlotProgressRange = 100;
                          ppd.PlotProgressPos = 0;
     
                          // Let's start the plot, at last
                          ppd.OnBeginPlot();
                          ppd.IsVisible = true;
                          pe.BeginPlot(ppd, null);
     
                          // We'll be plotting a single document
                          pe.BeginDocument(pi, doc.Name, null, 1, true,
                            // Let's plot to file
                           outputFileName);
                          // Which contains a single sheet
                          ppd.OnBeginSheet();
                          ppd.LowerSheetProgressRange = 0;
                          ppd.UpperSheetProgressRange = 100;
                          ppd.SheetProgressPos = 0;
                          Pt.PlotPageInfo ppi = new Pt.PlotPageInfo();
                          pe.BeginPage(ppi, pi, true, null);
                          pe.BeginGenerateGraphics(null);
                          pe.EndGenerateGraphics(null);
     
                          // Finish the sheet
                          pe.EndPage(null);
                          ppd.SheetProgressPos = 100;
                          ppd.OnEndSheet();
     
                          // Finish the document
                          pe.EndDocument(null);
     
                          // And finish the plot
                          ppd.PlotProgressPos = 100;
                          ppd.OnEndPlot();
                          pe.EndPlot(null);
                        }
                      }
                    }
                    else {
                      ed.WriteMessage("\nAnother plot is in progress.");
                    }
                  }
                }
                tr.Commit();
              }
            }
          }
          finally {
            Hs.WorkingDatabase = previewDb;
          }
        }
      }
    }
     
Просмотров: 5233
 
Автор темы   Непрочитано 14.05.2021, 15:20
#2
veb86

Проектировщик электрических сетей
 
Регистрация: 17.01.2014
Пенза
Сообщений: 176


Всем привет. Проблема решена. Надо было BACKGROUNDPLOT сделать равным 0. Печатает все быстро, НО почему то все ПДФпринтеры, не допечатывают, а оставляют чертежи на очереди. После закрытия акада, они моментально допечатываются. Исходя из моих потребностей, сей баг считаю для себя не критическим. Но если кто то знает решение, отзовитесь. Всем спасибо!
veb86 вне форума  
Ответ
Вернуться   Форум DWG.RU > Программное обеспечение > Программирование > .NET > Autocad2020. Программно долго печатает один чертеж pe.EndPlot(null);

Размещение рекламы
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Восстановление *.DWG Солидворкер AutoCAD 5249 01.02.2024 09:41
Civil 3D Из-за корридоров тормозит чертеж CHESNOK Вертикальные решения на базе AutoCAD 13 28.07.2014 17:23
Как объединить два чертежа (изометрия, плоский) в один? HARDCORE AutoCAD 4 24.02.2014 11:28
не печатает чертеж. Autocad 2010 Romeo1786 AutoCAD 6 25.03.2010 14:24
подскажите как перевести чертеж в JPEG миня AutoCAD 11 07.11.2007 17:19