Esempio n. 1
0
        public static void SetPageSize(Layout layout)
        {
            using (DocumentLock documentLock = Document.LockDocument())
            {
                using (Transaction setpageTransaction = Document.Database.TransactionManager.StartTransaction())
                {
                    using (PlotSettings plotSettings = new PlotSettings(layout.ModelType))
                    {
                        using (PlotSettingsValidator plotSettingsValidator = PlotSettingsValidator.Current)
                        {
                            layout = (Layout)setpageTransaction.GetObject(layout.ObjectId, OpenMode.ForWrite);

                            plotSettingsValidator.SetZoomToPaperOnUpdate(plotSettings, true);
                            plotSettingsValidator.SetPlotPaperUnits(plotSettings, PlotPaperUnit.Inches);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void SetLayoutPlotSetting()
        {
            Document       acDoc          = Application.DocumentManager.MdiActiveDocument;
            Database       acCurDb        = acDoc.Database;
            StandartCopier standartCopier = new StandartCopier();

            PlotConfigManager.SetCurrentConfig(standartCopier.Pc3Location);

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                Layout acLayout;

                LayoutModels = LayoutModels.OrderBy(x => x.Layout.TabOrder).ToList();

                foreach (var layout in LayoutModels)
                {
                    acLayout = acTrans.GetObject(layout.LayoutPlotId,
                                                 OpenMode.ForRead) as Layout;

                    if (acLayout == null)
                    {
                        continue;
                    }

                    LayoutManager lm = LayoutManager.Current;
                    lm.CurrentLayout = acLayout.LayoutName;

                    var plotArea = acLayout.Extents;
                    // Output the name of the current layout and its device
                    acDoc.Editor.WriteMessage("\nCurrent layout: " +
                                              acLayout.LayoutName);

                    acDoc.Editor.WriteMessage("\nCurrent device name: " +
                                              acLayout.PlotConfigurationName);

                    // 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 PlotConfigurationName property of the PlotSettings object
                    PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
                    //acPlSetVdr.SetCurrentStyleSheet(acPlSet, "monochrome.ctb");
                    bool isHor = layout.PrintModel.IsFormatHorizontal();

                    acPlSetVdr.SetPlotType(acPlSet, PlotType.Extents);
                    acPlSetVdr.SetPlotRotation(acPlSet, isHor ? PlotRotation.Degrees000 : PlotRotation.Degrees090);
                    acPlSetVdr.SetPlotWindowArea(acPlSet, Get2dExtentsFrom3d(plotArea));
                    acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit);

                    // Center the plot
                    acPlSetVdr.SetPlotCentered(acPlSet, true);

                    acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG_To_PDF_Uzle.pc3",
                                                        layout.CanonicalName);
                    acPlSetVdr.SetZoomToPaperOnUpdate(acPlSet, true);
                    // Update the layout
                    acLayout.UpgradeOpen();
                    acLayout.CopyFrom(acPlSet);

                    // Output the name of the new device assigned to the layout
                    acDoc.Editor.WriteMessage("\nNew device name: " +
                                              acLayout.PlotConfigurationName);

                    Active.Editor.Regen();
                }

                // Save the new objects to the database
                acTrans.Commit();
            }
        }
Esempio n. 3
0
        public static void SetPageSize(this Layout curlay, double width, double height, PlotPaperUnit ppu)
        {
            Document      doc    = Application.DocumentManager.MdiActiveDocument;
            Database      db     = doc.Database;
            LayoutManager laymgr = LayoutManager.Current;

            using (DocumentLock dl = doc.LockDocument())
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    using (PlotSettings pltset = new PlotSettings(curlay.ModelType))
                    {
                        pltset.CopyFrom(curlay);
                        PlotSettingsValidator psv = PlotSettingsValidator.Current;
                        Layout layout             = new Layout();

                        try
                        {
                            if (curlay.ObjectId != null)
                            {
                                layout = tr.GetObject(curlay.ObjectId, OpenMode.ForWrite) as Layout;
                            }
                        }

                        catch
                        {
                        }

                        #region Paper Types
                        try
                        {
                            if (!ppu.Equals(PlotPaperUnit.Inches))
                            {
                                psv.SetPlotPaperUnits(pltset, PlotPaperUnit.Inches);
                            }

                            if ((width == 11.00 && height == 17.00) || (width == 17.00 && height == 11.00))
                            {
                                psv.SetPlotConfigurationName(pltset,
                                                             "DWG To PDF.pc3",
                                                             "ANSI_full_bleed_B_(11.00_x_17.00_Inches)");
                            }

                            if ((width == 18.00 && height == 24.00) || (width == 24.00 && height == 18.00))
                            {
                                psv.SetPlotConfigurationName(pltset,
                                                             "DWG To PDF.pc3",
                                                             "ARCH_full_bleed_B_(18.00_x_24.00_Inches)");
                            }

                            else if ((width == 17.00 && height == 22.00) || (width == 22.00 && height == 17.00))
                            {
                                psv.SetPlotConfigurationName(pltset,
                                                             "DWG To PDF.pc3",
                                                             "ARCH_full_bleed_C_(17.00_x_22.00_Inches)");
                            }

                            else if ((width == 24.00 && height == 36.00) || (width == 36.00 && height == 24.00))
                            {
                                psv.SetPlotConfigurationName(pltset,
                                                             "DWG To PDF.pc3",
                                                             "ARCH_full_bleed_D_(24.00_x_36.00_Inches)");
                            }

                            else if ((width == 36.00 && height == 48.00) || (width == 48.00 && height == 36.00))
                            {
                                psv.SetPlotConfigurationName(pltset,
                                                             "DWG To PDF.pc3",
                                                             "ARCH_full_bleed_E_(36.00_x_48.00_Inches)");
                            }

                            else if ((width == 30.00 && height == 42.00) || (width == 42.00 && height == 30.00))
                            {
                                psv.SetPlotConfigurationName(pltset,
                                                             "DWG To PDF.pc3",
                                                             "ARCH_full_bleed_E1_(30.00_x_42.00_Inches)");
                            }

                            else
                            {
                                doc.Editor.WriteMessage("\n The drawing sizes were invalid, default setting will be used");
                                psv.SetPlotConfigurationName(pltset,
                                                             "DWG To PDF.pc3",
                                                             "ARCH_full_bleed_E_(36.00_x_48.00_Inches)");
                            }
                        }

                        catch
                        {
                            doc.Editor.WriteMessage("\n The drawing sizes were invalid, default setting will be used");
                            psv.SetPlotConfigurationName(pltset,
                                                         "DWG To PDF.pc3",
                                                         "ARCH_full_bleed_E_(36.00_x_48.00_Inches)");
                        }
                        #endregion

                        psv.SetZoomToPaperOnUpdate(pltset, true);

                        layout.UpgradeOpen();
                        layout.CopyFrom(pltset);

                        doc.Editor.WriteMessage("\n  " + "\nNew device name: " + layout.PlotConfigurationName);

                        tr.Commit();
                    }
                }
            }
        }