Example #1
0
        public void PlotLayout(_Db.Layout lay, string location)
        {
            using (_Pl.PlotInfo plotInfo = new _Pl.PlotInfo())
            {
                plotInfo.Layout = lay.ObjectId;

                using (_Db.PlotSettings plotSettings = new _Db.PlotSettings(lay.ModelType))
                {
                    plotSettings.CopyFrom(lay);
                    plotInfo.OverrideSettings = plotSettings;

                    _Db.PlotSettingsValidator plotValidator = _Db.PlotSettingsValidator.Current;

                    using (_Pl.PlotInfoValidator infoValidator = new _Pl.PlotInfoValidator())
                    {
                        infoValidator.MediaMatchingPolicy = _Pl.MatchingPolicy.MatchEnabled;
                        infoValidator.Validate(plotInfo);

                        using (_Pl.PlotProgressDialog dialog = new _Pl.PlotProgressDialog(false, 1, true))
                        {
                            write("Plotting: " + _c.doc.Name + " - " + lay.LayoutName);

                            engine.BeginPlot(dialog, null);
                            engine.BeginDocument(plotInfo, _c.doc.Name, null, 1, true, location);
                            using (_Pl.PlotPageInfo pageInfo = new _Pl.PlotPageInfo())
                            {
                                engine.BeginPage(pageInfo, plotInfo, true, null);
                            }
                            engine.BeginGenerateGraphics(null);

                            engine.EndGenerateGraphics(null);
                            engine.EndPage(null);
                            engine.EndDocument(null);
                            engine.EndPlot(null);
                        }
                    }
                }
            }
        }
Example #2
0
        private static bool PlotDwf(_AcDb.Layout lo, string dwfName)
        {
            try
            {
                var logMsg = string.Format("Erzeuge DWF-Datei für Layout '{0}'.", lo.LayoutName);
                log.Info(logMsg);
                _Editor.WriteMessage("\n" + logMsg);

                if (File.Exists(dwfName))
                {
                    File.Delete(dwfName);
                }

                var pi = new _AcPl.PlotInfo();
                pi.Layout = lo.Id;
                var ps = new _AcDb.PlotSettings(lo.ModelType);
                ps.CopyFrom(lo);
                var psv = _AcDb.PlotSettingsValidator.Current;
                psv.SetPlotConfigurationName(ps, _PlotterName, null);
                SetClosestMediaName(psv, _PlotterName, ps, lo.PlotPaperSize.X, lo.PlotPaperSize.Y, _AcDb.PlotPaperUnit.Millimeters, true);
                psv.SetPlotCentered(ps, true);

                pi.OverrideSettings = ps;
                var piv = new _AcPl.PlotInfoValidator();
                piv.MediaMatchingPolicy = _AcPl.MatchingPolicy.MatchEnabled;
                piv.Validate(pi);
                // You probably need to make sure background plotting is disabled. If the BACKGROUNDPLOT sysvar is set to 1 or 3, then PLOT will background plot (which is not what you want).
                // A PlotEngine does the actual plotting
                // (can also create one for Preview)
                if (_AcPl.PlotFactory.ProcessPlotState == _AcPl.ProcessPlotState.NotPlotting)
                {
                    var pe = _AcPl.PlotFactory.CreatePublishEngine();
                    using (pe)
                    {
                        // Create a Progress Dialog to provide info
                        // and allow the user to cancel
                        var ppd = new _AcPl.PlotProgressDialog(false, 1, true);
                        using (ppd)
                        {
                            ppd.set_PlotMsgString(_AcPl.PlotMessageIndex.DialogTitle, "Plot Fortschritt");
                            ppd.set_PlotMsgString(_AcPl.PlotMessageIndex.CancelJobButtonMessage, "Plot Abbrechen");
                            ppd.set_PlotMsgString(_AcPl.PlotMessageIndex.CancelSheetButtonMessage, "Sheet Abbrechen");
                            ppd.set_PlotMsgString(_AcPl.PlotMessageIndex.SheetSetProgressCaption, "Sheet Set Fortschritt");
                            ppd.set_PlotMsgString(_AcPl.PlotMessageIndex.SheetProgressCaption, "Sheet Fortschritt");
                            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, dwfName);
                            // Which contains a single sheet
                            ppd.OnBeginSheet();
                            ppd.LowerSheetProgressRange = 0;
                            ppd.UpperSheetProgressRange = 100;
                            ppd.SheetProgressPos        = 0;
                            var ppi = new _AcPl.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
                {
                    var msg = string.Format("Fehler beim Plot von Layout '{0}' in Zeichnung '{1}'! Es wird gerade geplottet!", lo.LayoutName, _Doc.Name);
                    log.Warn(msg);
                    _Editor.WriteMessage("\n" + msg);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                var msg = string.Format("Fehler beim Plot von Layout '{0}' in Zeichnung '{1}'! {2}", lo.LayoutName, _Doc.Name, ex.Message);
                log.Warn(msg);
                _Editor.WriteMessage("\n" + msg);
                return(false);
            }
            _NrPlots++;
            return(true);
        }