Esempio n. 1
0
        public string[,] GetCanonicalMediaName(Document acDoc)
        {
            Database acCurDb = acDoc.Database;
            PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;

            string[] acStrPlDevCol = GetPlotDevice(acDoc);
            string[,] acStrCanMedCol = new string[acStrPlDevCol.Length, 400];
            for (int k = 0; k < acStrPlDevCol.Length; k++)
            {
                using (PlotSettings acPlSet = new PlotSettings(true))
                {
                    bool checkOk = true;
                    try { acPlSetVdr.SetPlotConfigurationName(acPlSet, acStrPlDevCol[k], null); }
                    catch (Autodesk.AutoCAD.Runtime.Exception e) { string Error = e.Message; checkOk = false; }
                    if (!checkOk)
                    {
                        continue;
                    }
                    acPlSetVdr.RefreshLists(acPlSet);
                    StringCollection acCanMedCol = acPlSetVdr.GetCanonicalMediaNameList(acPlSet);
                    for (int l = 0; l < acCanMedCol.Count; l++)
                    {
                        acStrCanMedCol[k, l] = acCanMedCol[l];
                    }
                }
            }
            return(acStrCanMedCol);
        }
Esempio n. 2
0
        /// <summary>
        /// Refreshing list of plot style table
        /// </summary>
        /// <returns></returns>
        public static void RefreshStyles(ComboBox cboStyle)
        {
            // Update devices name
            PlotSettingsValidator psv = PlotSettingsValidator.Current;
            PlotSettings          ps  = new PlotSettings(true);

            psv.RefreshLists(ps);

            //Storing current style
            string curStyle = cboStyle.Text;

            // Append style to combobox's items
            StringCollection styleList = psv.GetPlotStyleSheetList();

            cboStyle.Items.Clear();
            for (int i = 0; i < styleList.Count; i++)
            {
                cboStyle.Items.Add(styleList[i]);
            }

            if (styleList.Contains(curStyle))
            {
                cboStyle.Text = curStyle;
            }
            else
            {
                // Setting default plot style table
                cboStyle.SelectedIndex = 0;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Get size of paper of specified device
        /// </summary>
        /// <param name="deviceName"></param>
        /// <param name="paper"></param>
        private static int[] GetPaperSize(string printer, string paper)
        {
            PlotSettingsValidator psv = PlotSettingsValidator.Current;
            PlotSettings          ps  = new PlotSettings(true);

            int[] size = null;
            int   w    = 0;
            int   h    = 0;

            psv.SetPlotConfigurationName(ps, printer, null);
            StringCollection mediaL = psv.GetCanonicalMediaNameList(ps);

            for (int i = 0; i < mediaL.Count; i++)
            {
                string s = (psv.GetLocaleMediaName(ps, i).ToString());
                if (s == paper)
                {
                    paper = mediaL[i];
                    psv.SetPlotConfigurationName(ps, printer, paper);
                    w = Convert.ToInt32(
                        Math.Max(ps.PlotPaperSize.X, ps.PlotPaperSize.Y));
                    h = Convert.ToInt32(
                        Math.Min(ps.PlotPaperSize.X, ps.PlotPaperSize.Y));
                    break;
                }
            }
            if (w != 0 && h != 0)
            {
                size = new int[] { w, h };
            }
            return(size);
        }
Esempio n. 4
0
        public void QueryMediaNames()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            LayoutManager         layMgr   = LayoutManager.Current;
            PlotSettingsValidator plSetVdr = PlotSettingsValidator.Current;


            db.TileMode = false;        //goto Paperspace if not already
            ed.SwitchToPaperSpace();    //turn PVP off

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Layout theLayout = (Layout)tr.GetObject(layMgr.GetLayoutId(layMgr.CurrentLayout), OpenMode.ForRead);

                PlotSettings np = new PlotSettings(theLayout.ModelType);
                np.CopyFrom(theLayout);

                //string canMedName = "ANSI_B_(11.00_x_17.00_Inches)"
                StringCollection canMedNames = plSetVdr.GetCanonicalMediaNameList(np);
                ed.WriteMessage("\n{0} MediaNames for {1}", canMedNames.Count, np.PlotConfigurationName);

                int i = 0;
                foreach (string canMedName in canMedNames)
                {
                    ed.WriteMessage("\n{0}: {1} {2}", i, canMedName, plSetVdr.GetLocaleMediaName(np, i));
                    i++;
                }
            }
        }
Esempio n. 5
0
        public void QueryPlotStyles()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            LayoutManager         layMgr   = LayoutManager.Current;
            PlotSettingsValidator plSetVdr = PlotSettingsValidator.Current;

            db.TileMode = false;        //goto Paperspace if not already
            ed.SwitchToPaperSpace();    //turn PVP off

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Layout theLayout = (Layout)tr.GetObject(layMgr.GetLayoutId(layMgr.CurrentLayout), OpenMode.ForRead);

                PlotSettings np = new PlotSettings(theLayout.ModelType);
                np.CopyFrom(theLayout);

                //string plotStyle="Monochrome.ctb"
                StringCollection plotStyles = plSetVdr.GetPlotStyleSheetList();
                ed.WriteMessage("\n{0} PlotStyles", plotStyles.Count);

                int i = 0;
                foreach (string plotStyleName in plotStyles)
                {
                    ed.WriteMessage("\n{0}: {1}", i, plotStyleName);
                    i++;
                }
            }
        }
Esempio n. 6
0
        public static string[] GetPlotDeviceAndCanonicalMediaName()
        {
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Editor   acDocEd = acDoc.Editor;
            PlotSettingsValidator acPlSetVdr  = PlotSettingsValidator.Current;
            StringCollection      acPlDevColl = acPlSetVdr.GetPlotDeviceList();

            for (int i = 0; i < acPlDevColl.Count; i++)
            {
                acDocEd.WriteMessage("\nNumber of device: {0}  -  Device name: {1}", i, acPlDevColl[i]);
            }
            int    n       = GetIntPrompt(acDoc, "Pick number of device to plot", 1, acPlDevColl.Count);
            string acPlDev = acPlDevColl[n];
            string acCanMed;

            Application.ShowAlertDialog("Plot device was chosen: " + acPlDev);
            using (PlotSettings acPlSet = new PlotSettings(true))
            {
                acPlSetVdr.SetPlotConfigurationName(acPlSet, acPlDev, null);
                acPlSetVdr.RefreshLists(acPlSet);
                StringCollection acCanMedColl = acPlSetVdr.GetCanonicalMediaNameList(acPlSet);
                for (int i = 0; i < acCanMedColl.Count; i++)
                {
                    acDocEd.WriteMessage("\nNumber of Canonical media name: {0}  -  Canonical media name: {1}", i, acCanMedColl[i]);
                }
                n        = GetIntPrompt(acDoc, "Pick number of Canonical media name", 1, acCanMedColl.Count);
                acCanMed = acCanMedColl[n];
                Application.ShowAlertDialog("Canonical media name: " + acCanMed);
            }

            return(new string[2] {
                acPlDev, acCanMed
            });
        }
Esempio n. 7
0
        //THIS IS TO GET LAYOUT
        public static void getlayout()
        {
            Document doc          = Application.DocumentManager.CurrentDocument;
            Database db           = doc.Database;
            ObjectId LayoutDictId = db.LayoutDictionaryId;

            PlotSettings plotSettings;

            using (doc.LockDocument())
            {
                LayoutManager layMan = LayoutManager.Current;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    DBDictionary layOutDict = (DBDictionary)tr.GetObject(LayoutDictId, OpenMode.ForRead);
                    foreach (DBDictionaryEntry kv in layOutDict)
                    {
                        string layoutName = kv.Key;
                        Layout layout     = (Layout)tr.GetObject(kv.Value, OpenMode.ForRead);
                        layMan.SetCurrentLayoutId(kv.Value);

                        BlockTableRecord      layoutBtr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForRead);
                        PlotSettingsValidator psVal     = PlotSettingsValidator.Current;
                        foreach (ObjectId id in layoutBtr)
                        {
                            DBObject loObj = tr.GetObject(id, OpenMode.ForRead);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Создание коллекции PlotSettingsInfo из пользовательских форматов
        /// в файле DWG to PDF.pc3
        /// Также в коллекцию будут включены форматы, начинающиеся с "ISO_A" - это поведение
        /// подлежит изменению
        /// </summary>
        /// <returns>Коллекция PlotSettingsInfo</returns>
        public static IEnumerable <PlotSettingsInfo> CreatePlotSettingsInfos()
        {
            string   PLOTTER_NAME = "DWG To PDF.pc3";
            Database db           = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                PlotSettingsValidator psv = PlotSettingsValidator.Current;
                PlotSettings          ps  = new PlotSettings(false);
                psv.RefreshLists(ps);
                psv.SetPlotConfigurationName(ps, PLOTTER_NAME, null);
                // Получаем список CanonicalMediaNames плоттера
                StringCollection canonicalMediaNames = psv.GetCanonicalMediaNameList(ps);

                string plotStyle = "acad.ctb";
                System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex(@"[\<>/?"":;*|,=`]");

                for (int nameIndex = 0; nameIndex < canonicalMediaNames.Count; nameIndex++)
                {
                    // Работаем только с пользовательскими форматами
                    if (canonicalMediaNames[nameIndex].Contains("UserDefinedMetric") ||
                        canonicalMediaNames[nameIndex].StartsWith("ISO_A"))
                    {
                        psv.SetPlotConfigurationName(ps, PLOTTER_NAME, canonicalMediaNames[nameIndex]);

                        psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Layout);
                        psv.SetPlotPaperUnits(ps, PlotPaperUnit.Millimeters);

                        psv.SetStdScaleType(ps, StdScaleType.StdScale1To1);
                        psv.SetUseStandardScale(ps, true);

                        psv.SetCurrentStyleSheet(ps, plotStyle);

                        if (canonicalMediaNames[nameIndex].StartsWith("ISO_A0"))
                        {
                            psv.SetPlotRotation(ps, PlotRotation.Degrees090);
                        }
                        else
                        {
                            psv.SetPlotRotation(ps, PlotRotation.Degrees000);
                        }

                        string plotSettingsName = re.Replace(psv.GetLocaleMediaName(ps, nameIndex), "");
                        if (string.IsNullOrEmpty(plotSettingsName))
                        {
                            plotSettingsName = canonicalMediaNames[nameIndex];
                        }
                        ps.PlotSettingsName = plotSettingsName;

                        PlotSettings newPS = new PlotSettings(false);
                        newPS.CopyFrom(ps);
                        yield return(new PlotSettingsInfo(newPS));
                    }
                }
            }
        }
Esempio n. 9
0
        //if the media size doesn't exist, this will search media list for best match
        // 8.5 x 11 should be there
        private static string setClosestMediaName(PlotSettingsValidator psv, PlotSettings ps,
                                                  double pageWidth, double pageHeight, bool matchPrintableArea)
        {
            //get all of the media listed for plotter
            StringCollection mediaList      = psv.GetCanonicalMediaNameList(ps);
            double           smallestOffest = 0.0;
            string           selectedMedia  = string.Empty;
            PlotRotation     selectedRot    = PlotRotation.Degrees000;

            foreach (string media in mediaList)
            {
                psv.SetCanonicalMediaName(ps, media);

                double mediaWidth  = ps.PlotPaperSize.X;
                double mediaHeight = ps.PlotPaperSize.Y;

                if (matchPrintableArea)
                {
                    mediaWidth  -= (ps.PlotPaperMargins.MinPoint.X + ps.PlotPaperMargins.MaxPoint.X);
                    mediaHeight -= (ps.PlotPaperMargins.MinPoint.Y + ps.PlotPaperMargins.MaxPoint.Y);
                }

                PlotRotation rot = PlotRotation.Degrees090;

                //check that we are not outside the media print area
                if (mediaWidth < pageWidth || mediaHeight < pageHeight)
                {
                    //Check if turning paper will work
                    if (mediaHeight < pageWidth || mediaWidth >= pageHeight)
                    {
                        //still too small
                        continue;
                    }
                    rot = PlotRotation.Degrees090;
                }

                double offset = Math.Abs(mediaWidth * mediaHeight - pageWidth * pageHeight);

                if (selectedMedia == string.Empty || offset < smallestOffest)
                {
                    selectedMedia  = media;
                    smallestOffest = offset;
                    selectedRot    = rot;

                    if (smallestOffest == 0)
                    {
                        break;
                    }
                }
            }
            psv.SetCanonicalMediaName(ps, selectedMedia);
            psv.SetPlotRotation(ps, selectedRot);
            return(selectedMedia);
        }
Esempio n. 10
0
        public string[] GetPlotStyle(Document acDoc)
        {
            Database acCurDb = acDoc.Database;
            PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
            StringCollection      acPlStlCol = acPlSetVdr.GetPlotStyleSheetList();

            string[] acStrPlStlCol = new string[acPlStlCol.Count];
            for (int k = 0; k < acPlStlCol.Count; k++)
            {
                acStrPlStlCol[k] = acPlStlCol[k];
            }
            return(acStrPlStlCol);
        }
Esempio n. 11
0
        public void Plot(string fileName, PlotEngine pe, PlotProgressDialog ppd)
        {
            using (Transaction trans = LayoutID.Database.TransactionManager.StartTransaction())
            {
                Layout layout = (Layout)trans.GetObject(LayoutID, OpenMode.ForRead);
                LayoutManager.Current.CurrentLayout = layout.LayoutName;

                PlotInfo plotInfo = new PlotInfo();
                plotInfo.Layout = LayoutID;

                // Set plot settings
                PlotSettings ps = new PlotSettings(layout.ModelType);
                ps.CopyFrom(layout);

                PlotSettingsValidator psv = PlotSettingsValidator.Current;
                psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Layout);
                psv.SetUseStandardScale(ps, true);
                psv.SetStdScaleType(ps, StdScaleType.StdScale1To1);

                /*PlotConfig pConfig = PlotConfigManager.SetCurrentConfig("DWG To PDF.pc3");
                 * var devices = psv.GetPlotDeviceList();*/
                psv.SetPlotConfigurationName(ps, "DWG To PDF.pc3", null);
                psv.RefreshLists(ps);
                var media = psv.GetCanonicalMediaNameList(ps);

                psv.SetPlotConfigurationName(ps, "DWG To PDF.pc3", GetMediaName());

                plotInfo.OverrideSettings = ps;
                PlotInfoValidator piv = new PlotInfoValidator();
                piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
                piv.Validate(plotInfo);

                pe.BeginDocument(plotInfo, fileName, null, 1, true, fileName);

                ppd.OnBeginSheet();
                ppd.LowerSheetProgressRange = 0;
                ppd.UpperSheetProgressRange = 100;
                ppd.SheetProgressPos        = 0;

                PlotPageInfo ppi = new PlotPageInfo();
                pe.BeginPage(ppi, plotInfo, true, null);
                pe.BeginGenerateGraphics(null);
                pe.EndGenerateGraphics(null);

                pe.EndPage(null);
                ppd.SheetProgressPos = 100;
                ppd.OnEndSheet();

                pe.EndDocument(null);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Refreshing list of plotter
        /// </summary>
        public static void RefreshPloter(ComboBox cboPlotter)
        {
            // Update devices name
            PlotSettingsValidator psv = PlotSettingsValidator.Current;
            PlotSettings          ps  = new PlotSettings(true);

            psv.RefreshLists(ps);

            // Store current device's name
            string curPlotter = cboPlotter.Text;

            //Append plotter/printer to combobox
            StringCollection devList = psv.GetPlotDeviceList();

            cboPlotter.Items.Clear();
            for (int i = 0; i < devList.Count; i++)
            {
                if (devList[i] == "None")
                {
                    continue;
                }
                cboPlotter.Items.Add(devList[i]);
            }
            if (devList.Contains(curPlotter))
            {
                cboPlotter.Text = curPlotter;
            }
            else
            {
                //Setting default plotter/printer
                if (devList.Contains("PDF reDirect v2_A3.pc3"))
                {
                    cboPlotter.SelectedIndex =
                        cboPlotter.Items.IndexOf("PDF reDirect v2_A3.pc3");
                }
                else if (devList.Contains("PDF reDirect v2"))
                {
                    cboPlotter.SelectedIndex =
                        cboPlotter.Items.IndexOf("PDF reDirect v2");
                }
                else if (devList.Contains("DWG To PDF.pc3"))
                {
                    cboPlotter.SelectedIndex =
                        cboPlotter.Items.IndexOf("DWG To PDF.pc3");
                }
                else
                {
                    cboPlotter.SelectedIndex = 0;
                }
            }
        }
Esempio n. 13
0
        public void Test2()
        {
            string path = "C:\\Users\\dyn1\\Desktop";

            System.IO.DirectoryInfo rootDir = new System.IO.DirectoryInfo(path);
            System.IO.FileInfo[]    dirs    = rootDir.GetFiles("*.dwg");
            var editor = Acad.DocumentManager.MdiActiveDocument.Editor;
            var Text   = new List <string>();
            PlotSettingsValidator psv = PlotSettingsValidator.Current;

            foreach (FileInfo dir in dirs)
            {
                editor.WriteMessage(Environment.NewLine + dir);
                Text.Add(dir.ToString());
                using (Database dwgDB = new Database(false, true))
                {
                    dwgDB.ReadDwgFile(dir.FullName, System.IO.FileShare.ReadWrite, false, "");


                    //Далее манипуляции с базой данных чертежа
                    using (Transaction acTrans = dwgDB.TransactionManager.StartTransaction())
                    {
                        List <Layout> layouts    = new List <Layout>();
                        DBDictionary  layoutDict = (DBDictionary)acTrans.GetObject(dwgDB.LayoutDictionaryId, OpenMode.ForRead);
                        editor.WriteMessage("Листы чертежа " + dir + ":");
                        Text.Add("Листы чертежа " + dir + ":");
                        foreach (DBDictionaryEntry id in layoutDict)
                        {
                            if (id.Key != "Model")
                            {
                                Layout ltr = (Layout)acTrans.GetObject((ObjectId)id.Value, OpenMode.ForRead);
                                layouts.Add(ltr);
                                editor.WriteMessage(Environment.NewLine + ltr.LayoutName);
                                editor.WriteMessage(Environment.NewLine + Math.Round(ltr.PlotPaperSize.X).ToString());
                                editor.WriteMessage(Environment.NewLine + Math.Round(ltr.PlotPaperSize.Y).ToString());
                                editor.WriteMessage(Environment.NewLine + ltr.PlotSettingsName);
                                Text.Add(ltr.LayoutName);
                                Text.Add(ltr.PlotPaperSize.ToString());
                                Text.Add(Math.Round(ltr.PlotPaperSize.X).ToString());
                                Text.Add(Math.Round(ltr.PlotPaperSize.Y).ToString());
                                Text.Add(ltr.PlotSettingsName);
                            }
                        }
                        System.IO.File.WriteAllLines("C:\\users\\dyn1\\desktop\\info2.txt", Text);
                        acTrans.Commit();
                    }
                }
            }
        }
Esempio n. 14
0
        public static void ChangePlotSetting()
        {
            // 获取当前文档和数据库,启动事务
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // 引用布局管理器LayoutManager
                LayoutManager acLayoutMgr;
                acLayoutMgr = LayoutManager.Current;

                // 获取当前布局,在命令行窗口显示布局名
                Layout acLayout;
                acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout),
                                             OpenMode.ForRead) as Layout;

                // 输出当前布局名和设备名
                acDoc.Editor.WriteMessage("\nCurrent layout: " +
                                          acLayout.LayoutName);

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

                // 从布局中获取PlotInfo
                PlotInfo acPlInfo = new PlotInfo();
                acPlInfo.Layout = acLayout.ObjectId;

                // 复制布局中的PlotSettings
                PlotSettings acPlSet = new PlotSettings(acLayout.ModelType);
                acPlSet.CopyFrom(acLayout);

                // 更新PlotSettings对象的PlotConfigurationName属性
                PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
                acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWF6 ePlot.pc3",
                                                    "ANSI_A_(8.50_x_11.00_Inches)");

                // 更新布局
                acLayout.UpgradeOpen();
                acLayout.CopyFrom(acPlSet);

                // 输出已更新的布局设备名
                acDoc.Editor.WriteMessage("\nNew device name: " +
                                          acLayout.PlotConfigurationName);

                // 将新对象保存到数据库
                acTrans.Commit();
            }
        }
Esempio n. 15
0
        public void Test()
        {
            PlotSettingsValidator psv = PlotSettingsValidator.Current;
            var Text   = new List <string>();
            var editor = Acad.DocumentManager.MdiActiveDocument.Editor;

            System.Collections.Specialized.StringCollection vs = psv.GetPlotDeviceList();
            foreach (var st in vs)
            {
                editor.WriteMessage(st.ToString() + Environment.NewLine);
                Text.Add(st.ToString());
            }
            using (PlotSettings ps = new PlotSettings(false))
            {
                foreach (var st in vs)
                {
                    editor.WriteMessage("Текущий/Selected: " + st.ToString() + Environment.NewLine);
                    Text.Add("Текущий/Selected: " + st.ToString());
                    if (st.ToString() == "AutoCAD PDF (High Quality Print).pc3")
                    {
                        PlotConfig config = PlotConfigManager.SetCurrentConfig(st.ToString());
                        PlotInfo   info   = new PlotInfo();
                        psv.SetPlotConfigurationName(ps, st.ToString(), null);
                        psv.RefreshLists(ps);
                        System.Collections.Specialized.StringCollection mediaName = psv.GetCanonicalMediaNameList(ps);
                        foreach (var media in mediaName)
                        {
                            editor.WriteMessage("Формат/Media name " + media.ToString() + Environment.NewLine);
                            Text.Add("Формат/Media name " + media.ToString());
                            MediaBounds bounds = config.GetMediaBounds(media.ToString());
                            editor.WriteMessage(Math.Round(bounds.PageSize.X).ToString() + Environment.NewLine);
                            editor.WriteMessage(Math.Round(bounds.PageSize.Y).ToString() + Environment.NewLine);
                            editor.WriteMessage(Math.Round(bounds.LowerLeftPrintableArea.X).ToString() + Environment.NewLine);
                            editor.WriteMessage(Math.Round(bounds.UpperRightPrintableArea.Y).ToString() + Environment.NewLine);
                            editor.WriteMessage(Math.Round(bounds.UpperRightPrintableArea.X).ToString() + Environment.NewLine);
                            editor.WriteMessage(Math.Round(bounds.LowerLeftPrintableArea.Y).ToString() + Environment.NewLine);
                            Text.Add(Math.Round(bounds.PageSize.X).ToString());
                            Text.Add(Math.Round(bounds.PageSize.Y).ToString());
                            Text.Add(Math.Round(bounds.LowerLeftPrintableArea.X).ToString());
                            Text.Add(Math.Round(bounds.UpperRightPrintableArea.Y).ToString());
                            Text.Add(Math.Round(bounds.UpperRightPrintableArea.X).ToString());
                            Text.Add(Math.Round(bounds.LowerLeftPrintableArea.Y).ToString());
                        }
                    }
                }
            }
            System.IO.File.WriteAllLines("C:\\users\\dyn1\\desktop\\info.txt", Text);
        }
Esempio n. 16
0
        public void QueryDetailedNamedPlotStyles()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            PlotSettingsValidator plSetVdr = PlotSettingsValidator.Current;


            db.TileMode = false;        //goto Paperspace if not already
            ed.SwitchToPaperSpace();    //turn PVP off

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                DBDictionary plotDict = (DBDictionary)db.PlotSettingsDictionaryId.GetObject(OpenMode.ForRead);
                ed.WriteMessage("\n{0} NamedPlotStyles", plotDict.Count);
                int i = 0;
                foreach (DBDictionaryEntry plotDictEntry in plotDict)
                {
                    PlotSettings np = (PlotSettings)tr.GetObject(plotDictEntry.Value, OpenMode.ForRead);
                    ed.WriteMessage("\n{0}: NamedPlotStyle: {1}", i, np.PlotSettingsName);
                    ed.WriteMessage("\n\tPlotter={0}", np.PlotConfigurationName);
                    ed.WriteMessage("\n\tPlotStyle={0}", np.CurrentStyleSheet);
                    ed.WriteMessage("\n\tPlotArea={0}", np.PlotType);

                    StringCollection medNames = plSetVdr.GetCanonicalMediaNameList(np);
                    for (int j = 0; j < medNames.Count; j++)
                    {
                        if (np.CanonicalMediaName.Equals(medNames[j], StringComparison.InvariantCultureIgnoreCase))
                        {
                            ed.WriteMessage("\n\tPlotPaper={0}/\t{1}", plSetVdr.GetLocaleMediaName(np, j), np.CanonicalMediaName);
                            break;
                        }
                    }

                    ed.WriteMessage("\n\tPaperSize={0}", np.PlotPaperSize.ToString());
                    ed.WriteMessage("\n\tPlot Rotation={0}", np.PlotRotation.ToString());
                    ed.WriteMessage("\n\tPaper Margins={0}, {1}", np.PlotPaperMargins.MinPoint.ToString(), np.PlotPaperMargins.MaxPoint.ToString());

                    i++;
                }

                tr.Commit();
            }
        }
Esempio n. 17
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. 18
0
        /// <summary>
        /// Get the paper that have size is the most closest specified size
        /// </summary>
        /// <param name="printer"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        private static string GetClosestPaper(string printer, int[] size)
        {
            int    w1        = size[0];
            int    h1        = size[1];
            string paper     = null;
            string tempPaper = null;

            PlotSettingsValidator psv = PlotSettingsValidator.Current;
            PlotSettings          ps  = new PlotSettings(true);

            psv.SetPlotConfigurationName(ps, printer, null);
            StringCollection mediaL = psv.GetCanonicalMediaNameList(ps);

            if (mediaL != null)
            {
                for (int i = 0; i < mediaL.Count; i++)
                {
                    paper = psv.GetLocaleMediaName(ps, i).ToString();
                    psv.SetPlotConfigurationName(ps, printer, paper);
                    int w2 = Convert.ToInt32(
                        Math.Max(ps.PlotPaperSize.X, ps.PlotPaperSize.Y));
                    int h2 = Convert.ToInt32(
                        Math.Min(ps.PlotPaperSize.X, ps.PlotPaperSize.Y));
                    if (w1 == w2 && h1 == h2)
                    {
                        break;
                    }

                    int o1 = w1; int o2 = h1;
                    int tO1, tO2;
                    tO1 = Math.Abs(w1 - w2);
                    tO2 = Math.Abs(h2 - h1);
                    if (tO1 * tO2 < o1 * o2)
                    {
                        tempPaper = paper;
                    }
                    paper = tempPaper;
                }
            }
            return(paper);
        }
Esempio n. 19
0
        /// <summary>
        /// Get list of paper size with specified device in cboPlotter
        ///     then append it to cboPaper
        /// </summary>
        /// <param name="cboPaper"></param>
        public static void RefreshPaper(ComboBox cboPaper, string printer)
        {
            // Storing current paper for selecting closest paper size with other printer
            string curPaper = cboPaper.Text;
            // Get size of current paper (if any)
            //int[] size = GetPaperSize(oldPrinter, curPaper);

            StringCollection      sc  = null;
            PlotSettingsValidator psv = PlotSettingsValidator.Current;
            PlotSettings          ps  = new PlotSettings(true);

            try
            {
                psv.SetPlotConfigurationName(ps, printer, null);
                sc = psv.GetCanonicalMediaNameList(ps);
                cboPaper.Items.Clear();
                if (sc != null)
                {
                    for (int i = 0; i < sc.Count; i++)
                    {
                        string s = (psv.GetLocaleMediaName(ps, i).ToString());
                        if (s != "")
                        {
                            cboPaper.Items.Add(s);
                        }
                    }
                }
            }
            catch (Exception ex) { }

            // Set default size
            if (cboPaper.Items.Contains(curPaper))
            {
                cboPaper.Text = curPaper;
            }
            else
            {
                cboPaper.SelectedIndex = 1;
            }
        }
Esempio n. 20
0
        /// <summary>
        /// 将打印设备及标准图纸尺寸清单存储到XML文件
        /// </summary>
        /// <param name="fileName">XML文件名</param>
        public static void DeviceMeidaToXML(string fileName)
        {
            XElement xroot = new XElement("Root");//创建一个XML根元素
            //获取当前打印设备列表
            PlotSettingsValidator psv     = PlotSettingsValidator.Current;
            StringCollection      devices = psv.GetPlotDeviceList();
            //创建打印设置对象,以获取设备拥有的图纸尺寸
            PlotSettings ps = new PlotSettings(true);

            foreach (string device in devices)//遍历打印设备
            {
                //创建一个名为Device的新元素
                XElement xDevice = new XElement("Device");
                //在Device元素下添加表示设备名称的属性
                xDevice.Add(new XAttribute("Name", device));
                //更新打印设备、图纸尺寸,以反映当前系统状态。
                psv.SetPlotConfigurationName(ps, device, null);
                psv.RefreshLists(ps);
                //获取打印设备的所有可用标准图纸尺寸的名称
                StringCollection medias = psv.GetCanonicalMediaNameList(ps);
                foreach (string media in medias)
                {
                    //如果为用户自定义图纸尺寸,则结束本次循环
                    if (media == "UserDefinedMetric")
                    {
                        continue;
                    }
                    //创建一个名为Media的新元素
                    XElement xMedia = new XElement("Media");
                    //在Media元素下添加表示图纸尺寸的属性
                    xMedia.Add(new XAttribute("Name", media));
                    xDevice.Add(xMedia); //添加Media元素到Device元素中
                }
                xroot.Add(xDevice);      //添加Device元素到根元素中
            }
            xroot.Save(fileName);        //保存XML文件
        }
Esempio n. 21
0
        public PageSetup(PlotSettings ps)
        {
            InitializeComponent();
            textBoxPlotScaleDrawingUint.LostFocus += new EventHandler(textBoxPlotScalePaperUint_TextChanged);
            textBoxPlotScalePaperUint.LostFocus   += new EventHandler(textBoxPlotScalePaperUint_TextChanged);
            textBoxPlotOffsetX.LostFocus          += new EventHandler(textBoxPlotOffsetX_TextChanged);
            textBoxPlotOffsetY.LostFocus          += new EventHandler(textBoxPlotOffsetX_TextChanged);
            textBoxDPI.LostFocus += new EventHandler(textBoxDPI_TextChanged);

            m_plotStg        = ps;
            m_plotSettingVal = PlotSettingsValidator.Current;

            // fill device list
            m_plotSettingVal.RefreshLists(m_plotStg);

            // is stored device name available in system ?
            String deviceName = m_plotStg.PlotConfigurationName;
            String mediaName  = m_plotStg.CanonicalMediaName;

            setPlotCfgName2Validator(deviceName, mediaName, false);

            FillDeviceCombo();

            FillPaperOrientation();
            comboBoxDevices.SelectedItem = deviceName;

            FillPlotAreaCombo(true);
            FillPlotOffset();

            FillScaleValues(true);
            FillPlotStyles();
            FillShadePlotQualityDPI(true);
            FillPlotStyleCombo(true);
            FillViewCombo(true);
            FillWindowArea();
        }
Esempio n. 22
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. 23
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();
                    }
                }
            }
        }
Esempio n. 24
0
        /// <summary>
        /// 创建布局和视口
        ///
        /// </summary>
        public static void CreateLayout(double[] B_Sta, Document doc, Database db)
        {
            //  var doc = Application.DocumentManager.MdiActiveDocument;

            if (doc == null)
            {
                return;
            }
            // var db = doc.Database;
            var ed     = doc.Editor;
            var ext    = new Extents2d();
            int k      = 0;// 100000 / 2600 / 3
            int zhushi = 0;
            //求布局数
            double Layoutnum = (B_Sta[B_Sta.Length - 1] - B_Sta[0]) / 350 / 3;

            for (int j = 0; j < Layoutnum + 1; j++)
            {
                using (var tr = db.TransactionManager.StartTransaction())
                {
                    //以读模式打开块表
                    BlockTable acBlkTbl;
                    acBlkTbl = tr.GetObject(db.BlockTableId,
                                            OpenMode.ForRead) as BlockTable;
                    //以写模式打开块表记录Paper空间
                    BlockTableRecord acBlkTblRec;
                    acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.PaperSpace],
                                               OpenMode.ForWrite) as BlockTableRecord;
                    //切换到Paper空间布局
                    Application.SetSystemVariable("TILEMODE", 0);
                    doc.Editor.SwitchToPaperSpace();

                    // Create and select a new layout tab
                    var id = LayoutManager.Current.CreateAndMakeLayoutCurrent("病害处理" + j);
                    // Open the created layout
                    var lay = (Layout)tr.GetObject(id, OpenMode.ForWrite);
                    // Make some settings on the layout and get its extents

                    /*     lay.SetPlotSettings(
                     *   //  "ISO_full_bleed_2A0_(1189.00_x_1682.00_MM)", // Try this big boy!
                     *     "ANSI_B_(11.00_x_17.00_Inches)",
                     *     "monochrome.ctb",
                     *     "DWF6 ePlot.pc3");*/
                    //从布局中获取PlotInfo
                    PlotInfo acPlInfo = new PlotInfo();
                    acPlInfo.Layout = lay.ObjectId;
                    //复制布局中的PlotSettings
                    PlotSettings acPlSet = new PlotSettings(lay.ModelType);
                    acPlSet.CopyFrom(lay);
                    //更新PlotSettings对象
                    PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
                    //设置打印区域
                    acPlSetVdr.SetPlotType(acPlSet,
                                           Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
                    //设置打印比例
                    acPlSetVdr.SetUseStandardScale(acPlSet, true);
                    acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit);
                    //居中打印
                    acPlSetVdr.SetPlotCentered(acPlSet, true);
                    ext = lay.GetMaximumExtents();
                    //绘制边框
                    //Create a polyline with two segments (3 points)
                    using (Autodesk.AutoCAD.DatabaseServices.Polyline acPoly = new Autodesk.AutoCAD.DatabaseServices.Polyline())

                    {
                        acPoly.AddVertexAt(0, new Point2d(0.2, 0.7), 0, 0, 0);
                        acPoly.AddVertexAt(1, new Point2d(0.2, ext.MaxPoint.Y - 0.3), 0, 0, 0);
                        acPoly.AddVertexAt(2, new Point2d(ext.MaxPoint.X - 0.13, ext.MaxPoint.Y - 0.3), 0, 0, 0);
                        acPoly.AddVertexAt(3, new Point2d(ext.MaxPoint.X - 0.13, 0.7), 0, 0, 0);
                        acPoly.AddVertexAt(4, new Point2d(0.2, 0.7), 0, 0, 0);
                        acPoly.LineWeight = LineWeight.LineWeight200;
                        //将新对象添加到块表记录和事务
                        acBlkTblRec.AppendEntity(acPoly);
                        tr.AddNewlyCreatedDBObject(acPoly, true);
                    }
                    //创建下方直线分隔
                    double[] Xiafangzuobiao = new double[] { 1.5, 4, 7, 7.5, 8.1, 8.6, 9.2, 9.7, 10.3, 10.8 };
                    for (int i = 0; i < Xiafangzuobiao.Length; i++)
                    {
                        WxxTU.Createline(acBlkTblRec, tr, Xiafangzuobiao[i], Xiafangzuobiao[i], 0.7, 1);
                    }
                    //创建下方需要填写的文字
                    string[] Xiafangwenzi        = new string[] { "路面病害处治设计图", "设计", "复核", "审核", "图号" };
                    double[] Xiafangwenzizuobiao = new double[] { 4.5, 7, 8.15, 9.2, 10.4 };
                    for (int i = 0; i < Xiafangwenzi.Length; i++)
                    {
                        //创建一个单行文字对象
                        using (DBText acText = new DBText())
                        {
                            acText.Position = new Point3d(Xiafangwenzizuobiao[i], 0.8, 0);
                            acText.Height   = 0.15;

                            acText.TextString = Xiafangwenzi[i];
                            acText.ColorIndex = 0;
                            //文字反向   acText.IsMirroredInX = false;
                            acText.Rotation = 0;
                            acBlkTblRec.AppendEntity(acText);
                            tr.AddNewlyCreatedDBObject(acText, true);


                            //释放DBObject对象
                        }
                    }
                    //创建上方直线分割
                    double[] Shangfangzuobiao = new double[] { 10, 10.8 };
                    for (int i = 0; i < Shangfangzuobiao.Length; i++)
                    {
                        WxxTU.Createline(acBlkTblRec, tr, Shangfangzuobiao[i], Shangfangzuobiao[i], ext.MaxPoint.Y - 0.3, ext.MaxPoint.Y - 0.65);
                    }
                    //创建上方需要填写的文字
                    string[] Shangfangwenzi = new string[] { "第" + j + "页", "共" + Math.Truncate(Layoutnum) + "页" };
                    for (int i = 0; i < Shangfangwenzi.Length; i++)
                    {
                        //创建一个单行文字对象
                        using (DBText acText = new DBText())
                        {
                            acText.Position = new Point3d(Shangfangzuobiao[i], ext.MaxPoint.Y - 0.5, 0);
                            acText.Height   = 0.15;

                            acText.TextString = Shangfangwenzi[i];
                            acText.ColorIndex = 0;
                            //文字反向   acText.IsMirroredInX = false;
                            acText.Rotation = 0;
                            acBlkTblRec.AppendEntity(acText);
                            tr.AddNewlyCreatedDBObject(acText, true);


                            //释放DBObject对象
                        }
                    }
                    //创建桩号起终点注释
                    double[] Sta_Y = new double[] { 2.75, 5, 7.1 };
                    for (int i = 0; i < 3; i++)
                    {
                        using (DBText acText = new DBText())
                        {
                            acText.Position = new Point3d(9, Sta_Y[i], 0);
                            acText.Height   = 0.15;

                            acText.TextString = WxxTU.Station_Double2Str(B_Sta[0] + 350 * (zhushi - 3)) + "-" + WxxTU.Station_Double2Str(B_Sta[0] + 350 * (zhushi - 2));
                            acText.ColorIndex = 0;
                            //文字反向   acText.IsMirroredInX = false;
                            acText.Rotation = 0;
                            acBlkTblRec.AppendEntity(acText);
                            tr.AddNewlyCreatedDBObject(acText, true);
                            zhushi++;

                            //释放DBObject对象
                        }
                    }

                    //创建多个视口
                    for (int i = 0; i < 3; i++)
                    {
                        lay.ApplyToViewport(
                            tr, i,
                            vp =>
                        {
                            // Size the viewport according to the extents calculated when
                            // we set the PlotSettings (device, page size, etc.)
                            // Use the standard 10% margin around the viewport
                            // (found by measuring pixels on screenshots of Layout1, etc.)

                            vp.ResizeViewport(ext, 0.8, 2 * i + 1, k);
                            k++;

                            /* // Adjust the view so that the model contents fit
                             * if (ValidDbExtents(db.Extmin, db.Extmax))
                             * {
                             *   vp.FitContentToViewport(new Extents3d(db.Extmin, db.Extmax),0.8);
                             * }
                             *
                             * // Finally we lock the view to prevent meddling*/


                            vp.Locked = true;
                        }
                            );
                    }
                    //  k++;

                    // Commit the transaction
                    tr.Commit();
                }
            }
            // Zoom so that we can see our new layout, again with a little padding

            /*    ed.Command("_.ZOOM", "_E");
             *  ed.Command("_.ZOOM", ".7X");
             *  ed.Regen();*/
        }
Esempio n. 25
0
        public void QueryPaperSize()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            LayoutManager         layMgr   = LayoutManager.Current;
            PlotSettingsValidator plSetVdr = PlotSettingsValidator.Current;

            Dictionary <string, Point2d> customPaperSize = new Dictionary <string, Point2d>(StringComparer.CurrentCultureIgnoreCase);

            customPaperSize.Add("A4", new Point2d(210.0, 297.0));
            customPaperSize.Add("A3", new Point2d(297.0, 420.0));
            customPaperSize.Add("A2", new Point2d(420.0, 594.0));
            customPaperSize.Add("A1", new Point2d(594.0, 841.0));
            customPaperSize.Add("A0", new Point2d(841.0, 1189.0));
            customPaperSize.Add("A0Plus", new Point2d(841.0, 1480.0));
            customPaperSize.Add("A0+", new Point2d(841.0, 1470.0));
            customPaperSize.Add("GBKN", new Point2d(594.0, 1051.0));

            customPaperSize.Add("4Z", new Point2d(297.0, 750.0));
            customPaperSize.Add("5Z", new Point2d(297.0, 930.0));
            customPaperSize.Add("6Z", new Point2d(297.0, 1110.0));
            customPaperSize.Add("7Z", new Point2d(297.0, 1290.0));

            customPaperSize.Add("Z3", new Point2d(297.0, 594.0));
            customPaperSize.Add("Z4", new Point2d(297.0, 841.0));
            customPaperSize.Add("Z6", new Point2d(297.0, 1189.0));

            customPaperSize.Add("3A4", new Point2d(297.0, 630.0));
            customPaperSize.Add("4A4", new Point2d(297.0, 841.0));
            customPaperSize.Add("5A4", new Point2d(297.0, 1050.0));
            customPaperSize.Add("6A4", new Point2d(297.0, 1260.0));
            customPaperSize.Add("7A4", new Point2d(297.0, 1470.0));



            db.TileMode = false;        //goto Paperspace if not already
            ed.SwitchToPaperSpace();    //turn PVP off

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Layout theLayout = (Layout)tr.GetObject(layMgr.GetLayoutId(layMgr.CurrentLayout), OpenMode.ForWrite);

                // Get the PlotInfo from the layout
                PlotInfo plInfo = new PlotInfo();
                plInfo.Layout = theLayout.ObjectId;

                PlotSettings np = new PlotSettings(theLayout.ModelType);
                np.CopyFrom(theLayout);

                string devName = "DWG To PDF.pc3";  //OceTds600.pc3
                plSetVdr.SetPlotConfigurationName(np, devName, null);
                plSetVdr.RefreshLists(np);

                StringCollection canMedNames = plSetVdr.GetCanonicalMediaNameList(np);
                for (int i = 0; i < canMedNames.Count; i++)
                {
                    plSetVdr.SetCanonicalMediaName(np, canMedNames[i]);
                    plSetVdr.RefreshLists(np);
                    string medName = plSetVdr.GetLocaleMediaName(np, i);
                    //ed.WriteMessage("\n{0}: Can. MediaName={1}/{2}", i, np.CanonicalMediaName, medName);
                    if (medName.Equals("ISO A1 (841.00 x 594.00 MM)"))
                    {
                        ed.WriteMessage("\n{0}: Can. MediaName={1}/{2}", i, np.CanonicalMediaName, medName);
                        Point2d pSize = np.PlotPaperSize;
                        ed.WriteMessage("\n\tPaperSize={0}", pSize.ToString());
                        PlotRotation pRot = np.PlotRotation;
                        ed.WriteMessage("\n\tPlot Rotation={0}", pRot.ToString());
                        Extents2d pM = np.PlotPaperMargins;
                        ed.WriteMessage("\n\tPaper Margins={0}, {1}", pM.MinPoint.ToString(), pM.MaxPoint.ToString());
                    }
                }
            }
        }
Esempio n. 26
0
        public static void ChangePlotSetting()
        {
            // Get the current document and database, and start a transaction
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Reference the Layout Manager
                LayoutManager acLayoutMgr;
                acLayoutMgr = LayoutManager.Current;

                // Get the current layout and output its name in the Command Line window
                Layout acLayout;

                LayoutModelCollection layoutModelCollection = new LayoutModelCollection();
                layoutModelCollection.ListLayouts("Model");
                var layouts = layoutModelCollection.LayoutModels.OrderBy(x => x.Layout.TabOrder).ToList();

                foreach (var layout in layouts)
                {
                    acLayout = acTrans.GetObject(layout.LayoutPlotId,
                                                 OpenMode.ForRead) as Layout;
                    if (acLayout != null)
                    {
                        // 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.SetPlotConfigurationName(acPlSet, "DWG_To_PDF_Uzle.pc3",
                                                            "UserDefinedMetric (891.00 x 420.00мм)");

                        acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit);
                        // Center the plot
                        //acPlSetVdr.SetPlotCentered(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);
                    }
                }

                // Save the new objects to the database
                acTrans.Commit();
            }
        }
Esempio n. 27
0
        //set up plotinfo
        static public PlotInfo plotSetUp(Extents2d window, Transaction tr, Database db, Editor ed, bool scaleToFit, bool pdfout)
        {
            using (tr)
            {
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
                // We need a PlotInfo object linked to the layout
                PlotInfo pi = new PlotInfo();
                pi.Layout = btr.LayoutId;

                //current layout
                Layout lo = (Layout)tr.GetObject(btr.LayoutId, OpenMode.ForRead);

                // We need a PlotSettings object based on the layout settings which we then customize
                PlotSettings ps = new PlotSettings(lo.ModelType);
                ps.CopyFrom(lo);

                //The PlotSettingsValidator helps create a valid PlotSettings object
                PlotSettingsValidator psv = PlotSettingsValidator.Current;

                //set rotation
                psv.SetPlotRotation(ps, orientation(window)); //perhaps put orientation after window setting window??

                // We'll plot the window, centered, scaled, landscape rotation
                psv.SetPlotWindowArea(ps, window);
                psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);//breaks here on some drawings

                // Set the plot scale
                psv.SetUseStandardScale(ps, true);
                if (scaleToFit == true)
                {
                    psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
                }
                else
                {
                    psv.SetStdScaleType(ps, StdScaleType.StdScale1To1);
                }

                // Center the plot
                psv.SetPlotCentered(ps, true);//finding best location

                //get printerName from system settings
                PrinterSettings settings           = new PrinterSettings();
                string          defaultPrinterName = settings.PrinterName;

                psv.RefreshLists(ps);
                // Set Plot device & page size
                // if PDF set it up for some PDF plotter
                if (pdfout == true)
                {
                    psv.SetPlotConfigurationName(ps, "DWG to PDF.pc3", null);
                    var mns = psv.GetCanonicalMediaNameList(ps);
                    if (mns.Contains("ANSI_expand_A_(8.50_x_11.00_Inches)"))
                    {
                        psv.SetCanonicalMediaName(ps, "ANSI_expand_A_(8.50_x_11.00_Inches)");
                    }
                    else
                    {
                        string mediaName = setClosestMediaName(psv, ps, 8.5, 11, true);
                    }
                }
                else
                {
                    psv.SetPlotConfigurationName(ps, defaultPrinterName, null);
                    var mns = psv.GetCanonicalMediaNameList(ps);
                    if (mns.Contains("Letter"))
                    {
                        psv.SetCanonicalMediaName(ps, "Letter");
                    }
                    else
                    {
                        string mediaName = setClosestMediaName(psv, ps, 8.5, 11, true);
                    }
                }

                //rebuilts plotter, plot style, and canonical media lists
                //(must be called before setting the plot style)
                psv.RefreshLists(ps);

                //ps.ShadePlot = PlotSettingsShadePlotType.AsDisplayed;
                //ps.ShadePlotResLevel = ShadePlotResLevel.Normal;

                //plot options
                //ps.PrintLineweights = true;
                //ps.PlotTransparency = false;
                //ps.PlotPlotStyles = true;
                //ps.DrawViewportsFirst = true;
                //ps.CurrentStyleSheet

                // Use only on named layouts - Hide paperspace objects option
                // ps.PlotHidden = true;

                //psv.SetPlotRotation(ps, PlotRotation.Degrees180);


                //plot table needs to be the custom heavy lineweight for the Uphol specs
                psv.SetCurrentStyleSheet(ps, "monochrome.ctb");

                // We need to link the PlotInfo to the  PlotSettings and then validate it
                pi.OverrideSettings = ps;
                PlotInfoValidator piv = new PlotInfoValidator();
                piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
                piv.Validate(pi);

                return(pi);
            }
        }
Esempio n. 28
0
        //打印模型布局的范围
        //打印到DWF文件

        //[CommandMethod("PlotCurrentLayout")]
        /// <summary>
        /// 打印输出单个文件
        /// </summary>
        /// <param name="LayerName"></param>
        /// <param name="FileName"></param>
        /// <param name="outputFilePath"></param>
        /// <param name="printer"></param>
        /// <param name="paperFormat"></param>
        public static void PlotCurrentLayout(string LayerName, string FileName, string outputFilePath, string printer, string paperFormat)
        {
            // 获取当前文档和数据库,启动事务
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;
            Editor   ed      = acDoc.Editor;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // 获取图层
                LayerTable acLyrTbl;
                acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) as LayerTable;

                // 将活动图层修改为第一个,即图层0
                acCurDb.Clayer = acLyrTbl[LayerName];
                LayerTableRecord acLayerTblRec = acTrans.GetObject(acLyrTbl[LayerName], OpenMode.ForWrite) as LayerTableRecord;
                acLayerTblRec.IsOff = false; //显示该图层

                // 引用布局管理器LayoutManager
                LayoutManager acLayoutMgr;
                acLayoutMgr = LayoutManager.Current;

                // 获取当前布局,在命令行窗口显示布局名字
                Layout acLayout;
                acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout),
                                             OpenMode.ForRead) as Layout;

                // 从布局中获取PlotInfo
                PlotInfo acPlInfo = new PlotInfo();
                acPlInfo.Layout = acLayout.ObjectId;

                // 复制布局中的PlotSettings
                PlotSettings acPlSet = new PlotSettings(acLayout.ModelType);
                acPlSet.CopyFrom(acLayout);

                // 更新PlotSettings对象
                PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;

                //// 获取打印设备
                //StringCollection deviceList = acPlSetVdr.GetPlotDeviceList();

                //// 打印设备列表-MessageBox形式
                //foreach (string d in deviceList)
                //{
                //    ed.WriteMessage("打印设备:" + d + "\n");
                //}

                //// 获取纸张列表
                //StringCollection mediaList = acPlSetVdr.GetCanonicalMediaNameList(acPlSet);

                //ed.WriteMessage("图纸种类:" + Convert.ToString(mediaList.Count) + " 个\n");
                //foreach (string m in mediaList)
                //{
                //    ed.WriteMessage("打印图纸:" + m + "\n");
                //}

                // 设置打印区域
                acPlSetVdr.SetPlotType(acPlSet,
                                       Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);

                // 设置打印比例
                acPlSetVdr.SetUseStandardScale(acPlSet, true);
                acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit);

                // 居中打印
                acPlSetVdr.SetPlotCentered(acPlSet, true);

                // 设置使用的打印设备
                //acPlSetVdr.SetPlotConfigurationName(acPlSet, "PostScript Level 2.pc3",
                //"ANSI_A_(8.50_x_11.00_Inches)");
                //设置采用的打印设备与纸张格式
                acPlSetVdr.SetPlotConfigurationName(acPlSet, printer,
                                                    paperFormat);


                // 用上述设置信息覆盖PlotInfo对象,
                // 不会将修改保存回布局
                acPlInfo.OverrideSettings = acPlSet;

                // 验证打印信息
                PlotInfoValidator acPlInfoVdr = new PlotInfoValidator();
                acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
                acPlInfoVdr.Validate(acPlInfo);

                // 检查是否有正在处理的打印任务
                if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
                {
                    using (PlotEngine acPlEng = PlotFactory.CreatePublishEngine())
                    {
                        // 使用PlotProgressDialog对话框跟踪打印进度
                        PlotProgressDialog acPlProgDlg = new PlotProgressDialog(false,
                                                                                1,
                                                                                true);

                        using (acPlProgDlg)
                        {
                            // 定义打印开始时显示的状态信息
                            acPlProgDlg.set_PlotMsgString(PlotMessageIndex.DialogTitle,
                                                          "Plot Progress");
                            acPlProgDlg.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage,
                                                          "Cancel Job");
                            acPlProgDlg.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage,
                                                          "Cancel Sheet");
                            acPlProgDlg.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption,
                                                          "Sheet Set Progress");
                            acPlProgDlg.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption,
                                                          "Sheet Progress");

                            // 设置打印进度范围
                            acPlProgDlg.LowerPlotProgressRange = 0;
                            acPlProgDlg.UpperPlotProgressRange = 100;
                            acPlProgDlg.PlotProgressPos        = 0;

                            // 显示打印进度对话框
                            acPlProgDlg.OnBeginPlot();
                            acPlProgDlg.IsVisible = true;

                            // 开始打印
                            acPlEng.BeginPlot(acPlProgDlg, null);

                            string opFile = outputFilePath + LayerName;
                            // 定义打印输出
                            acPlEng.BeginDocument(acPlInfo,
                                                  acDoc.Name,
                                                  null,
                                                  1,
                                                  true,
                                                  opFile);

                            // 显示当前打印任务的有关信息
                            //acPlProgDlg.set_PlotMsgString(PlotMessageIndex.Status,
                            //                              "Plotting: " + acDoc.Name + " - " +
                            //                              acLayout.LayoutName);
                            acPlProgDlg.set_PlotMsgString(PlotMessageIndex.Status,
                                                          "Plotting: " + acDoc.Name + " - " +
                                                          LayerName);

                            // 设置图纸进度范围
                            acPlProgDlg.OnBeginSheet();
                            acPlProgDlg.LowerSheetProgressRange = 0;
                            acPlProgDlg.UpperSheetProgressRange = 100;
                            acPlProgDlg.SheetProgressPos        = 0;

                            // 打印第一张图/布局
                            PlotPageInfo acPlPageInfo = new PlotPageInfo();
                            acPlEng.BeginPage(acPlPageInfo,
                                              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);
                        }
                    }
                }


                acLayerTblRec.IsOff = true; //关闭该图层
                printFlag           = true;
                //ed.WriteMessage("打印完成 \n");
            }
        }
Esempio n. 29
0
        public void PlotToPDF(string filePath)
        {
            if (File.Exists(filePath))
            {
                Application.ShowAlertDialog("File already exists");
                return;
            }

            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;
            Database db  = doc.Database;



            Transaction tr =
                db.TransactionManager.StartTransaction();

            using (tr)
            {
                // We'll be plotting the current layout

                Application.DocumentManager.MdiActiveDocument = doc;
                LayoutManager.Current.CurrentLayout           = GetFirstLayout();

                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
                Layout           lo  = (Layout)tr.GetObject(btr.LayoutId, OpenMode.ForRead);

                // We need a PlotInfo object
                // linked to the layout

                PlotInfo pi = new PlotInfo();
                pi.Layout = btr.LayoutId;

                // We need a PlotSettings object
                // based on the layout settings
                // which we then customize

                PlotSettings ps = new PlotSettings(lo.ModelType);
                ps.CopyFrom(lo);

                // The PlotSettingsValidator helps
                // create a valid PlotSettings object

                PlotSettingsValidator psv =
                    PlotSettingsValidator.Current;

                // We'll plot the extents, centered and
                // scaled to fit

                psv.SetPlotType(
                    ps,
                    Autodesk.AutoCAD.DatabaseServices.PlotType.Extents
                    );
                psv.SetUseStandardScale(ps, true);
                psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
                psv.SetPlotCentered(ps, true);
                psv.RefreshLists(ps);
                //psv.SetCurrentStyleSheet(lo, "E:\\Plottefil\\COWI_EL-v00.ctb");

                // We'll use the standard DWF PC3, as
                // for today we're just plotting to file

                psv.SetPlotConfigurationName(
                    ps,
                    "DWG to PDF.pc3",
                    "ISO_A0_(841.00_x_1189.00_MM)"
                    );

                // We need to link the PlotInfo to the
                // PlotSettings and then validate it

                pi.OverrideSettings = ps;
                PlotInfoValidator piv = new PlotInfoValidator();
                piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
                piv.Validate(pi);

                // A PlotEngine does the actual plotting
                // (can also create one for Preview)

                if (PlotFactory.ProcessPlotState ==
                    ProcessPlotState.NotPlotting)
                {
                    PlotEngine pe = PlotFactory.CreatePublishEngine();
                    using (pe)
                    {
                        // Create a Progress Dialog to provide info
                        // and allow the user to cancel

                        PlotProgressDialog ppd = new PlotProgressDialog(true, 1, true);
                        using (ppd)
                        {
                            ppd.set_PlotMsgString(
                                PlotMessageIndex.DialogTitle,
                                "Custom Plot Progress"
                                );
                            ppd.set_PlotMsgString(
                                PlotMessageIndex.CancelJobButtonMessage,
                                "Cancel Job"
                                );
                            ppd.set_PlotMsgString(
                                PlotMessageIndex.CancelSheetButtonMessage,
                                "Cancel Sheet"
                                );
                            ppd.set_PlotMsgString(
                                PlotMessageIndex.SheetSetProgressCaption,
                                "Sheet Set Progress"
                                );
                            ppd.set_PlotMsgString(
                                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
                                filePath);

                            // Which contains a single sheet

                            ppd.OnBeginSheet();

                            ppd.LowerSheetProgressRange = 0;
                            ppd.UpperSheetProgressRange = 100;
                            ppd.SheetProgressPos        = 0;

                            PlotPageInfo ppi = new 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."
                        );
                }
            }
        }
Esempio n. 30
0
        static public void PublishViews2MultiSheet()
        {
            pwdWindow = new PasswordWindow();
            pwdWindow.ShowDialog();
            Document         doc         = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            Database         db          = doc.Database;
            Editor           ed          = doc.Editor;
            StringCollection viewsToPlot = new StringCollection();

            viewsToPlot.Add("Test1");
            viewsToPlot.Add("Test2");
            using (Transaction Tx = db.TransactionManager.StartTransaction())
            {
                ObjectId layoutId = LayoutManager.Current.GetLayoutId(LayoutManager.Current.CurrentLayout);
                Layout   layout   = Tx.GetObject(layoutId, OpenMode.ForWrite) as Layout;
                foreach (String viewName in viewsToPlot)
                {
                    PlotSettings plotSettings = new PlotSettings(layout.ModelType);
                    plotSettings.CopyFrom(layout);
                    PlotSettingsValidator psv = PlotSettingsValidator.Current;
                    psv.SetPlotConfigurationName(plotSettings, "DWF6 ePlot.pc3", "ANSI_A_(8.50_x_11.00_Inches)");
                    psv.RefreshLists(plotSettings);
                    psv.SetPlotViewName(plotSettings, viewName);
                    psv.SetPlotType(plotSettings, Autodesk.AutoCAD.DatabaseServices.PlotType.View);
                    psv.SetUseStandardScale(plotSettings, true);
                    psv.SetStdScaleType(plotSettings, StdScaleType.ScaleToFit);
                    psv.SetPlotCentered(plotSettings, true);
                    psv.SetPlotRotation(plotSettings, PlotRotation.Degrees000);
                    psv.SetPlotPaperUnits(plotSettings, PlotPaperUnit.Inches);
                    plotSettings.PlotSettingsName = String.Format("{0}{1}", viewName, "PS");
                    plotSettings.PrintLineweights = true;
                    plotSettings.AddToPlotSettingsDictionary(db);
                    Tx.AddNewlyCreatedDBObject(plotSettings, true);
                    psv.RefreshLists(plotSettings);
                    layout.CopyFrom(plotSettings);
                }
                Tx.Commit();
            }
            short bgPlot = (short)Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("BACKGROUNDPLOT");

            Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("BACKGROUNDPLOT", 0);
            string dwgFileName = Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("DWGNAME") as string;
            string dwgPath     = Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("DWGPREFIX") as string;

            using (Transaction Tx = db.TransactionManager.StartTransaction())
            {
                DsdEntryCollection collection     = new DsdEntryCollection();
                ObjectId           activeLayoutId = LayoutManager.Current.GetLayoutId(LayoutManager.Current.CurrentLayout);
                foreach (String viewName in viewsToPlot)
                {
                    Layout   layout = Tx.GetObject(activeLayoutId, OpenMode.ForRead) as Layout;
                    DsdEntry entry  = new DsdEntry();
                    entry.DwgName      = dwgPath + dwgFileName;
                    entry.Layout       = layout.LayoutName;
                    entry.Title        = viewName;
                    entry.NpsSourceDwg = entry.DwgName;
                    entry.Nps          = String.Format("{0}{1}", viewName, "PS");
                    collection.Add(entry);
                }
                dwgFileName = dwgFileName.Substring(0, dwgFileName.Length - 4);
                DsdData dsdData = new DsdData();
                dsdData.SheetType       = SheetType.MultiDwf;
                dsdData.ProjectPath     = dwgPath;
                dsdData.DestinationName = dsdData.ProjectPath + dwgFileName + ".dwf";
                /*Get password from user*/
                dsdData.Password = pwdWindow.passwordBox.Password;
                if (System.IO.File.Exists(dsdData.DestinationName))
                {
                    System.IO.File.Delete(dsdData.DestinationName);
                }
                dsdData.SetDsdEntryCollection(collection);

                /*DsdFile */
                string dsdFile = dsdData.ProjectPath + dwgFileName + ".dsd";
                dsdData.WriteDsd(dsdFile);
                System.IO.StreamReader sr = new System.IO.StreamReader(dsdFile);
                string str = sr.ReadToEnd();
                sr.Close();
                str = str.Replace("PromptForDwfName=TRUE",
                                  "PromptForDwfName=FALSE");
                /*Prompts User to Enter Password and Reconfirms*/
                //str = str.Replace("PromptForPwd=FALSE",
                //                   "PromptForPwd=TRUE");
                //str = str.Replace("PwdProtectPublishedDWF=FALSE",
                //                   "PwdProtectPublishedDWF=TRUE");
                int           occ        = 0;
                int           index      = str.IndexOf("Setup=");
                int           startIndex = 0;
                StringBuilder dsdText    = new StringBuilder();
                while (index != -1)
                {
                    String str1 = str.Substring(startIndex, index + 6 - startIndex);
                    dsdText.Append(str1);
                    dsdText.Append(String.Format("{0}{1}", viewsToPlot[occ], "PS"));
                    startIndex = index + 6;
                    index      = str.IndexOf("Setup=", index + 6);
                    if (index == -1)
                    {
                        dsdText.Append(str.Substring(startIndex, str.Length - startIndex));
                    }
                    occ++;
                }
                System.IO.StreamWriter sw = new System.IO.StreamWriter(dsdFile);
                sw.Write(dsdText.ToString());
                sw.Close();
                dsdData.ReadDsd(dsdFile);
                System.IO.File.Delete(dsdFile);
                PlotConfig plotConfig = PlotConfigManager.SetCurrentConfig("DWF6 ePlot.pc3");
                Publisher  publisher  = Autodesk.AutoCAD.ApplicationServices.Core.Application.Publisher;
                publisher.PublishExecute(dsdData, plotConfig);
                Tx.Commit();
            }
            Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot);
        }