Author Topic: Problem with "plot into png-picture"  (Read 1573 times)

0 Members and 1 Guest are viewing this topic.

MarioR

  • Newt
  • Posts: 64
Problem with "plot into png-picture"
« on: March 09, 2016, 05:41:37 AM »
Hello,

i use the below function to plot an selected area into png picture.
But with some drawings it create a blank image!
I have tested on non working drawing with copy all entities to new drawing. On the new drawing work it fine.
On the debugging i have explore the PlottSettings and PlotInfo. The only has changed is PlotInfo.MergeStyle and
of course the ObjectIds for layouts etc.
Does anyone have such an effect already observed?
The not working drawings I not allowed to post (internal company). But they are also> 50MB.

regards Mario

Code - C#: [Select]
  1.             if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
  2.             {
  3.                 if (imageType != enImageType.unknown)
  4.                 {
  5.                     if (transaction.StartTransaction())
  6.                     {
  7.                         Object bgPlott = Application.GetSystemVariable("BACKGROUNDPLOT");
  8.                         Application.SetSystemVariable("BACKGROUNDPLOT", 0);
  9.                         BlockTableRecord acBlockTableRecord = transaction.getObject(transaction.AcDatabase.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;
  10.                         Layout acLayout = transaction.getObject(acBlockTableRecord.LayoutId, OpenMode.ForRead) as Layout;
  11.  
  12.                         PlotInfo acPlotInfo = new PlotInfo();
  13.                         acPlotInfo.Layout = acLayout.ObjectId;
  14.  
  15.                         PlotSettings acPlotSettings = new PlotSettings(acLayout.ModelType);
  16.                         acPlotSettings.ScaleLineweights = false;
  17.                         acPlotSettings.ShowPlotStyles = false;
  18.                         acPlotSettings.ShadePlot = PlotSettingsShadePlotType.AsDisplayed;
  19.                         acPlotSettings.ShadePlotResLevel = ShadePlotResLevel.Normal;
  20.                         acPlotSettings.PrintLineweights = true;
  21.                         acPlotSettings.PlotTransparency = true;
  22.                         acPlotSettings.DrawViewportsFirst = true;
  23.                         acPlotSettings.PlotPlotStyles = false;
  24.                        
  25.                        
  26.                         PlotSettingsValidator acPlotSettingsValidator = PlotSettingsValidator.Current;
  27.                         acPlotSettingsValidator.SetPlotWindowArea(acPlotSettings, new Extents2d(ll, ur));
  28.                         acPlotSettingsValidator.SetPlotType(acPlotSettings, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
  29.                         // Maßstab
  30.                         acPlotSettingsValidator.SetStdScaleType(acPlotSettings, StdScaleType.ScaleToFit);
  31.                         //acPlotSettingsValidator.SetStdScale(acPlotSettings, dotsXPerUnit);
  32.                         acPlotSettingsValidator.SetPlotCentered(acPlotSettings, true);
  33.                         acPlotSettingsValidator.SetZoomToPaperOnUpdate(acPlotSettings, true);
  34.                         acPlotSettingsValidator.SetPlotRotation(acPlotSettings, PlotRotation.Degrees000);
  35.  
  36.                         // Plotter setzten
  37.                         if (imageType == enImageType.jpg)
  38.                             acPlotSettingsValidator.SetPlotConfigurationName(acPlotSettings, "PublishToWeb JPG.pc3", "VGA_(640.00_x_480.00_Pixels)");
  39.                         else
  40.                             acPlotSettingsValidator.SetPlotConfigurationName(acPlotSettings, "PublishToWeb PNG.pc3", "VGA_(640.00_x_480.00_Pixels)");
  41.  
  42.  
  43.  
  44.                         acPlotInfo.OverrideSettings = acPlotSettings;                        
  45.                         PlotInfoValidator acPlotInfoValidator = new PlotInfoValidator();
  46.                         // Bildgröße setzten
  47.  
  48.                         acPlotInfoValidator.Validate(acPlotInfo);
  49.                         if (acPlotInfo.IsValidated)
  50.                         {
  51.                             using (PlotEngine acPlotEngine = PlotFactory.CreatePublishEngine())
  52.                             {
  53.                                 using (PlotProgressDialog acPlotProgressDialog = new PlotProgressDialog(false, 1, true))
  54.                                 {
  55.                                     if (acPlotEngine != null)
  56.                                     {
  57.                                         acPlotProgressDialog.LowerPlotProgressRange = 0;
  58.                                         acPlotProgressDialog.UpperPlotProgressRange = 100;
  59.                                         acPlotProgressDialog.OnBeginPlot();
  60.                                         acPlotProgressDialog.IsVisible = true;
  61.  
  62.                                         acPlotEngine.BeginPlot(acPlotProgressDialog, null);
  63.  
  64.                                         acPlotEngine.BeginDocument(acPlotInfo, transaction.AcDocument.Name, null, 1, true, exportFileName);
  65.                                         PlotPageInfo acPlotPageInfo = new PlotPageInfo();
  66.  
  67.                                         acPlotProgressDialog.LowerSheetProgressRange = 0;
  68.                                         acPlotProgressDialog.UpperSheetProgressRange = 100;
  69.                                         acPlotProgressDialog.set_PlotMsgString(PlotMessageIndex.Status, "Erzeuge [" + exportFileName + "]");
  70.                                         acPlotProgressDialog.OnBeginSheet();
  71.                                         acPlotEngine.BeginPage(acPlotPageInfo, acPlotInfo, true, null);
  72.  
  73.                                         acPlotEngine.BeginGenerateGraphics(null);
  74.                                         acPlotEngine.EndGenerateGraphics(null);
  75.  
  76.                                         acPlotEngine.EndPage(null);
  77.                                         acPlotProgressDialog.SheetProgressPos = 100;
  78.                                         acPlotProgressDialog.OnEndSheet();
  79.  
  80.                                         acPlotEngine.EndDocument(null);
  81.  
  82.                                         acPlotProgressDialog.PlotProgressPos = 100;
  83.                                         acPlotProgressDialog.OnEndPlot();
  84.  
  85.                                         acPlotEngine.EndPlot(null);
  86.  
  87.  
  88.                                         acPlotProgressDialog.IsVisible = false;
  89.                                     }
  90.                                 }
  91.                             }
  92.                         }
  93.                         acPlotInfoValidator.Dispose();
  94.                         acPlotInfo.Dispose();
  95.                         acPlotSettings.Dispose();
  96.                         Application.SetSystemVariable("BACKGROUNDPLOT", bgPlott);
  97.                     }
  98.                 }
  99.             }
  100.  

MarioR

  • Newt
  • Posts: 64
Re: Problem with "plot into png-picture"
« Reply #1 on: April 13, 2016, 09:35:13 AM »
Hello,

is some Time ago. I have reactivate my project but i havnt found a solution.
The current Code is on the bottom(sorry output and message are in German):
This code works in a class into a framework. This Code only is not runable, is more posted for chekup the plottingsettings ;-)

On the goodDWG.dwg work it fine, but on the badDWG.dwg he dosnt work.

Enviroment is Civil3d 2014 also as an plain AutoCAD 2014.

What is the diferent between the DWG and what is the cause for the empty picture?

My suggestion going to a scale problem.

regards Mario

Code: [Select]
        public Boolean generate(clTransaction transaction, clBeanPixelFormat thisPixelformat)
        {
            if (transaction == null) throw new ArgumentNullException("transaction darf nicht null sein");
            Boolean result = false;
            if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
            {
                if (transaction.StartTransaction())
                {
                    try
                    {
                        Object bgPlott = Application.GetSystemVariable("BACKGROUNDPLOT");
                        Application.SetSystemVariable("BACKGROUNDPLOT", 0);
                        BlockTableRecord acBlockTableRecord = transaction.getObject(transaction.AcDatabase.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;
                        Layout acLayout = transaction.getObject(acBlockTableRecord.LayoutId, OpenMode.ForRead) as Layout;

                        PlotInfo acPlotInfo = new PlotInfo();
                        acPlotInfo.Layout = acLayout.ObjectId;

                        PlotSettings acPlotSettings = new PlotSettings(acLayout.ModelType);
                        PlotConfigInfo acPlotConfigInfo = new PlotConfigInfo();

                        acPlotSettings.CopyFrom(acLayout);

                        if (acLayout.ModelType)
                        {
                            acPlotSettings.ScaleLineweights = true;
                            acPlotSettings.ShowPlotStyles = false;
                            acPlotSettings.ShadePlot = PlotSettingsShadePlotType.AsDisplayed;
                            acPlotSettings.ShadePlotResLevel = ShadePlotResLevel.Normal;
                            acPlotSettings.PrintLineweights = true;
                            acPlotSettings.PlotTransparency = true;
                            acPlotSettings.DrawViewportsFirst = true;
                            acPlotSettings.PlotPlotStyles = false;
                        }
                        else
                        {
                        }

                        PlotSettingsValidator acPlotSettingsValidator = PlotSettingsValidator.Current;
                        // Plotter setzten
                        acPlotSettingsValidator.SetPlotConfigurationName(acPlotSettings, "PNG_PLOTTER.pc3", thisPixelformat.AcadPlottFormatName);
                        acPlotSettingsValidator.SetStdScaleType(acPlotSettings, StdScaleType.ScaleToFit);
                        acPlotSettingsValidator.SetPlotCentered(acPlotSettings, true);
                        acPlotSettingsValidator.SetPlotWindowArea(acPlotSettings, new Extents2d(ll, ur));
                        acPlotSettingsValidator.SetPlotType(acPlotSettings, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
                        //acPlotSettingsValidator.SetStdScale(acPlotSettings, dotsXPerUnit);

                        acPlotSettingsValidator.SetPlotCentered(acPlotSettings, true);
                        acPlotSettingsValidator.SetZoomToPaperOnUpdate(acPlotSettings, true);
                        acPlotSettingsValidator.SetPlotRotation(acPlotSettings, PlotRotation.Degrees000);

                        acPlotInfo.OverrideSettings = acPlotSettings;

                        PlotInfoValidator acPlotInfoValidator = new PlotInfoValidator();

                        acPlotInfoValidator.MediaMatchingPolicy = MatchingPolicy.MatchDisabled;
                        acPlotInfoValidator.Validate(acPlotInfo);
                        if (acPlotInfo.IsValidated)
                        {
                            using (PlotEngine acPlotEngine = PlotFactory.CreatePublishEngine())
                            {
                                using (PlotProgressDialog acPlotProgressDialog = new PlotProgressDialog(false, 1, true))
                                {
                                    if (acPlotEngine != null)
                                    {
                                        acPlotProgressDialog.LowerPlotProgressRange = 0;
                                        acPlotProgressDialog.UpperPlotProgressRange = 100;
                                        acPlotProgressDialog.OnBeginPlot();
                                        acPlotProgressDialog.IsVisible = true;

                                        acPlotEngine.BeginPlot(acPlotProgressDialog, null);

                                        acPlotEngine.BeginDocument(acPlotInfo, transaction.AcDocument.Name, null, 1, true, exportFileName);
                                        PlotPageInfo acPlotPageInfo = new PlotPageInfo();

                                        acPlotProgressDialog.LowerSheetProgressRange = 0;
                                        acPlotProgressDialog.UpperSheetProgressRange = 100;
                                        acPlotProgressDialog.set_PlotMsgString(PlotMessageIndex.Status, "Erzeuge [" + exportFileName + "]");
                                        acPlotProgressDialog.OnBeginSheet();
                                        acPlotEngine.BeginPage(acPlotPageInfo, acPlotInfo, true, null);

                                        acPlotEngine.BeginGenerateGraphics(null);
                                        acPlotEngine.EndGenerateGraphics(null);

                                        acPlotEngine.EndPage(null);
                                        acPlotProgressDialog.SheetProgressPos = 100;
                                        acPlotProgressDialog.OnEndSheet();

                                        acPlotEngine.EndDocument(null);

                                        acPlotProgressDialog.PlotProgressPos = 100;
                                        acPlotProgressDialog.OnEndPlot();

                                        acPlotEngine.EndPlot(null);


                                        acPlotProgressDialog.IsVisible = false;
                                    }
                                }
                            }
                        }
                        acPlotInfoValidator.Dispose();
                        acPlotInfo.Dispose();
                        acPlotSettings.Dispose();
                        Application.SetSystemVariable("BACKGROUNDPLOT", bgPlott);
                    }
                    catch (Exception ex)
                    {
                        clEditor.LogException(ex);
                    }
                }
            }
            else
                clEditor.writeStringLF("\nAnderer Plot in Arbeit!");
           

MarioR

  • Newt
  • Posts: 64
Re: Problem with "plot into png-picture"
« Reply #2 on: April 21, 2016, 07:17:24 AM »
Hello,

problem is solved. I dont known that the coordinates on "acPlotSettingsValidator.SetPlotWindowArea(acPlotSettings, new Extents2d(ll, ur));" (ll,ul) must DCS (display coordinate system). Now i transform the UCS-coordinates into DCS and it works.

regards Mario