Example #1
1
        private void PlotFiles()
        {
            DsdEntryCollection dsdCol = new DsdEntryCollection();

            int indexfile = 0;

            title = $"Печать {filesDwg.Length} файлов dwg...";

            foreach (var fileDwg in filesDwg)
            {
                if (HostApplicationServices.Current.UserBreak())
                    throw new Exception(General.CanceledByUser);

                indexfile++;
                using (var dbTemp = new Database(false, true))
                {
                    dbTemp.ReadDwgFile(fileDwg, FileOpenMode.OpenForReadAndAllShare, false, "");
                    dbTemp.CloseInput(true);
                    using (var t = dbTemp.TransactionManager.StartTransaction())
                    {
                        DBDictionary layoutDict = (DBDictionary)dbTemp.LayoutDictionaryId.GetObject(OpenMode.ForRead);

                        List<Layout> layouts = new List<Layout>();
                        foreach (DBDictionaryEntry entry in layoutDict)
                        {
                            if (entry.Key != "Model")
                            {
                                if (!entry.Value.IsErased)
                                {
                                    var layout = entry.Value.GetObject(OpenMode.ForRead) as Layout;
                                    layouts.Add(layout);
                                }
                            }
                        }
                        // Фильтр листов
                        if (Options.FilterState)
                        {
                            layouts = FilterLayouts(layouts, Options);
                        }

                        List<Tuple<Layout, DsdEntry>> layoutsDsd = new List<Tuple<Layout, DsdEntry>>();
                        foreach (var layout in layouts)
                        {
                            DsdEntry dsdEntry = new DsdEntry();
                            dsdEntry.Layout = layout.LayoutName;
                            dsdEntry.DwgName = fileDwg;
                            //dsdEntry.Nps = "Setup1";
                            dsdEntry.NpsSourceDwg = fileDwg;
                            dsdEntry.Title = indexfile + "-" + layout.LayoutName;
                            layoutsDsd.Add(new Tuple<Layout, DsdEntry>(layout, dsdEntry));
                            //dsdCol.Add(dsdEntry);
                        }

                        if (Options.SortTabOrName)
                        {
                            layoutsDsd.Sort((l1, l2) => l1.Item1.TabOrder.CompareTo(l2.Item1.TabOrder));
                        }
                        else
                        {
                            layoutsDsd.Sort((l1, l2) => l1.Item1.LayoutName.CompareTo(l2.Item1.LayoutName));
                        }
                        layoutsDsd.ForEach(l => dsdCol.Add(l.Item2));
                        t.Commit();
                    }
                }
            }
            PublisherDSD(dsdCol);
        }
Example #2
0
        private void PublisherDSD(DsdEntryCollection collection)
        {
            var dsdFile  = Path.Combine(dir, filePdfOutputName + ".dsd");
            var destFile = Path.Combine(dir, filePdfOutputName + ".pdf");

            Application.SetSystemVariable("BACKGROUNDPLOT", 0);
            using (var dsd = new DsdData())
            {
                dsd.SetDsdEntryCollection(collection);
                dsd.SheetType        = SheetType.MultiPdf;
                dsd.IsSheetSet       = true;
                dsd.NoOfCopies       = 1;
                dsd.IsHomogeneous    = false;
                dsd.DestinationName  = destFile;
                dsd.SheetSetName     = "PublisherSet";
                dsd.PromptForDwfName = false;
                PostProcessDSD(dsd, dsdFile);
            }

            using (var progressDlg = new PlotProgressDialog(false, collection.Count, true))
            {
                progressDlg.IsVisible = true;
                var publisher = Application.Publisher;
                PlotConfigManager.SetCurrentConfig("clk-PDF.pc3");
                publisher.PublishDsd(dsdFile, progressDlg);
                progressDlg.Destroy();
            }
        }
Example #3
0
        public void Plot()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;

            dir = Path.GetDirectoryName(doc.Name);
            filePdfOutputName = Path.GetFileNameWithoutExtension(doc.Name);
            using (var dsdCol = new DsdEntryCollection())
            {
                using (var t = doc.TransactionManager.StartTransaction())
                {
                    var layouts = GetLayouts(doc.Database);
                    foreach (var layout in layouts)
                    {
                        var dsdEntry = new DsdEntry
                        {
                            Layout       = layout.LayoutName,
                            DwgName      = doc.Name,
                            NpsSourceDwg = doc.Name,
                            Title        = layout.LayoutName
                        };
                        dsdCol.Add(dsdEntry);
                    }

                    t.Commit();
                }

                PublisherDSD(dsdCol);
            }
        }
        //private void HandleCancelledOrFailedPublish(object sender, PublishEventArgs e)
        //{
        //    app.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Error : publishing failed/cancelled...", e.ToString());
        //}

        //private void HandleEndPublish(object sender, PublishEventArgs e)
        //{
        //    app.DocumentManager.MdiActiveDocument.Editor.WriteMessage("All publishing tasks finished...", e.ToString());
        //}

        //private void HandleBeginPublishingSheet(object sender, BeginPublishingSheetEventArgs e)
        //{
        //    app.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Error : while publishing...", e.ToString());
        //}

        private bool TryCreateDSD()
        {
            using (DsdData dsd = new DsdData())
                using (DsdEntryCollection dsdEntries = CreateDsdEntryCollection(this._layouts))
                {
                    if (dsdEntries == null || dsdEntries.Count <= 0)
                    {
                        return(false);
                    }

                    if (!Directory.Exists(this._outputDir))
                    {
                        Directory.CreateDirectory(this._outputDir);
                    }

                    this._numberOfsheets = dsdEntries.Count;

                    dsd.SetDsdEntryCollection(dsdEntries);

                    dsd.SetUnrecognizedData("PwdProtectPublishedDWF", "FALSE");
                    dsd.SetUnrecognizedData("PromptForPwd", "FALSE");
                    //dsd.SheetType = SheetType.MultiDwf;
                    dsd.SheetType       = SheetType.MultiPdf; //previously MultiDwf -- check
                    dsd.NoOfCopies      = 1;
                    dsd.DestinationName = this._pdfFile;
                    dsd.IsHomogeneous   = false;
                    dsd.LogFilePath     = Path.Combine(this._outputDir, _logFile);

                    PostProcessDSD(dsd);

                    return(true);
                }
        }
Example #5
0
            // Creates the DSD file from a template (default options)
            private bool TryCreateDSD(string layerName)
            {
                using (DsdData dsd = new DsdData())
                    using (DsdEntryCollection dsdEntries = CreateDsdEntryCollection(this.layouts, Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database, layerName))
                    {
                        if (dsdEntries == null || dsdEntries.Count <= 0)
                        {
                            return(false);
                        }

                        if (!Directory.Exists(this.outputDir))
                        {
                            Directory.CreateDirectory(this.outputDir);
                        }

                        this.sheetNum = dsdEntries.Count;

                        dsd.SetDsdEntryCollection(dsdEntries);

                        dsd.SetUnrecognizedData("PwdProtectPublishedDWF", "FALSE");
                        dsd.SetUnrecognizedData("PromptForPwd", "FALSE");
                        dsd.SetUnrecognizedData("INCLUDELAYER", "FALSE");
                        dsd.NoOfCopies      = 1;
                        dsd.DestinationName = this.outputFile;
                        dsd.IsHomogeneous   = false;
                        dsd.LogFilePath     = Path.Combine(this.outputDir, LOG);


                        PostProcessDSD(dsd);

                        return(true);
                    }
            }
Example #6
0
        public void PublishPackage(PrintPackageModel package)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;

            short bgPlot = (short)Application.GetSystemVariable("BACKGROUNDPLOT");

            Application.SetSystemVariable("BACKGROUNDPLOT", 0);

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                DsdEntryCollection collection = new DsdEntryCollection();
                foreach (var layoutModel in package.Layouts)
                {
                    DsdEntry entry = new DsdEntry();
                    entry.DwgName      = package.DwgPath + package.DwgFileName;
                    entry.Layout       = layoutModel.LayoutName;
                    entry.Title        = "Layout_" + layoutModel.LayoutName;
                    entry.NpsSourceDwg = entry.DwgName;
                    entry.Nps          = "Setup1";

                    collection.Add(entry);
                }

                DsdData dsdData = new DsdData();
                dsdData.SheetType       = SheetType.MultiPdf; //SheetType.MultiPdf
                dsdData.ProjectPath     = package.DwgPath;
                dsdData.DestinationName =
                    $"{dsdData.ProjectPath}{package.PdfFileName}.pdf";
                if (System.IO.File.Exists(dsdData.DestinationName))
                {
                    System.IO.File.Delete(dsdData.DestinationName);
                }
                dsdData.SetDsdEntryCollection(collection);
                string dsdFile = $"{dsdData.ProjectPath}{package.PdfFileName}.dsd";

                dsdData.WriteDsd(dsdFile);
                dsdData.ReadDsd(dsdFile);

                System.IO.File.Delete(dsdFile);
                var plotConfig = PlotConfigManager.SetCurrentConfig("DWG_To_PDF_Uzle.pc3");
                var publisher  = Application.Publisher;

                publisher.AboutToBeginPublishing +=
                    new Autodesk.AutoCAD.Publishing.
                    AboutToBeginPublishingEventHandler(
                        Publisher_AboutToBeginPublishing);
                dsdData.PromptForDwfName = false;
                publisher.PublishExecute(dsdData, plotConfig);
                tr.Commit();
            }

            Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot);
        }
        private DsdEntryCollection CreateDsdEntryCollection(IEnumerable <Layout> layouts)
        {
            DsdEntryCollection entries = new DsdEntryCollection();

            foreach (Layout layout in layouts)
            {
                DsdEntry dsdEntry = new DsdEntry();
                dsdEntry.DwgName = this.dwgFile;
                dsdEntry.Layout  = layout.LayoutName;
                dsdEntry.Title   = Path.GetFileNameWithoutExtension(this.dwgFile) + "-" + layout.LayoutName;
                dsdEntry.Nps     = layout.TabOrder.ToString();
                entries.Add(dsdEntry);
            }
            return(entries);
        }
        private DsdEntryCollection CreateDsdEntryCollection(IEnumerable<Layout> layouts)
        {
            DsdEntryCollection entries = new DsdEntryCollection();

             foreach (Layout layout in layouts)
             {
            DsdEntry dsdEntry = new DsdEntry();
            dsdEntry.DwgName = this.dwgFile;
            dsdEntry.Layout = layout.LayoutName;
            dsdEntry.Title = Path.GetFileNameWithoutExtension(this.dwgFile) + "-" + layout.LayoutName;
            dsdEntry.Nps = layout.TabOrder.ToString();
            entries.Add(dsdEntry);
             }
             return entries;
        }
        private DsdEntryCollection CreateDsdEntryCollection(IEnumerable <Layout> layouts)
        {
            DsdEntryCollection entries = new DsdEntryCollection();

            foreach (Layout layout in layouts)
            {
                //layout.Initialize();  --//giving exception
                DsdEntry dsdEntry = new DsdEntry();
                dsdEntry.DwgName = this._dwgFile;
                dsdEntry.Layout  = layout.LayoutName;
                //File.AppendAllText("D:\\layout_names.txt", layout.LayoutName);     //test
                dsdEntry.Title = Path.GetFileNameWithoutExtension(this._dwgFile) + "-" + layout.LayoutName;
                dsdEntry.Nps   = layout.TabOrder.ToString();
                entries.Add(dsdEntry);
            }
            return(entries);
        }
Example #10
0
        private DsdEntryCollection CreateDsdEntryCollection([NotNull] IEnumerable <Layout> layouts)
        {
            var entries = new DsdEntryCollection();

            foreach (var layout in layouts)
            {
                var dsdEntry = new DsdEntry()
                {
                    DwgName = dwgFile,
                    Layout  = layout.LayoutName,
                    Title   = Path.GetFileNameWithoutExtension(dwgFile) + "-" + layout.LayoutName,
                    Nps     = layout.TabOrder.ToString()
                };
                entries.Add(dsdEntry);
            }

            return(entries);
        }
Example #11
0
            // Creates an entry collection (one per layout) for the DSD file
            private DsdEntryCollection CreateDsdEntryCollection(ArrayList layouts, Database db, string layerName)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    DsdEntryCollection entries = new DsdEntryCollection();

                    foreach (ObjectId layoutId in layouts)
                    {
                        Layout layout = tr.GetObject(layoutId, OpenMode.ForRead) as Layout;

                        DsdEntry dsdEntry = new DsdEntry();
                        dsdEntry.DwgName = this.dwgFile;
                        dsdEntry.Layout  = layout.LayoutName;
                        dsdEntry.Title   = Path.GetFileNameWithoutExtension(this.dwgFile) + "-" + layerName + "-" + layout.LayoutName;
                        dsdEntry.Nps     = layout.TabOrder.ToString();

                        entries.Add(dsdEntry);
                    }

                    tr.Commit();
                    return(entries);
                }
            }
Example #12
0
        static public void PublishExecute()
        {
            try
            {
                string dsdFilePath = "c:\\Temp\\publisher.dsd";
                string dsdLogPath  = "c:\\Temp\\logdwf.log";
                string dwfDestPath = "c:\\Temp\\PublisherTest.dwf";

                DsdEntryCollection collection = new DsdEntryCollection();
                DsdEntry           entry;

                entry              = new DsdEntry();
                entry.Layout       = "Layout1";
                entry.DwgName      = "c:\\Temp\\Drawing1.dwg";
                entry.NpsSourceDwg = entry.DwgName;
                entry.Title        = "Sheet1";
                collection.Add(entry);

                entry              = new DsdEntry();
                entry.Layout       = "Layout1";
                entry.DwgName      = "c:\\Temp\\Drawing2.dwg";
                entry.NpsSourceDwg = entry.DwgName;
                entry.Title        = "Sheet2";
                collection.Add(entry);

                DsdData dsd = new DsdData();
                dsd.SetDsdEntryCollection(collection);
                dsd.IsSheetSet      = true;
                dsd.LogFilePath     = dsdLogPath;
                dsd.SheetType       = SheetType.MultiDwf;
                dsd.NoOfCopies      = 1;
                dsd.DestinationName = dwfDestPath;
                dsd.SheetSetName    = "PublisherSet";
                dsd.WriteDsd(dsdFilePath);

                //Workaround to avoid promp for dwf file name
                //set PromptForDwfName=FALSE in dsdData using StreamReader/StreamWriter
                System.IO.StreamReader sr = new System.IO.StreamReader(dsdFilePath);
                string str = sr.ReadToEnd();
                sr.Close();

                str = str.Replace("PromptForDwfName=TRUE", "PromptForDwfName=FALSE");
                System.IO.StreamWriter sw = new System.IO.StreamWriter(dsdFilePath);
                sw.Write(str);
                sw.Close();

                dsd.ReadDsd(dsdFilePath);

                Autodesk.AutoCAD.PlottingServices.PlotConfigManager.SetCurrentConfig(
                    "DWF6 ePlot.pc3");

                AboutToBeginPublishingEventHandler Publisher_AboutToBeginPublishing = null;
                Application.Publisher.AboutToBeginPublishing +=
                    new Autodesk.AutoCAD.Publishing.AboutToBeginPublishingEventHandler(
                        Publisher_AboutToBeginPublishing);

                Application.Publisher.PublishExecute(
                    dsd,
                    Autodesk.AutoCAD.PlottingServices.PlotConfigManager.CurrentConfig);

                System.IO.File.Delete(dsdFilePath);
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.Message);
            }
        }
Example #13
0
            public void PublishNew(string pdfLocation, string layerName)
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;

                Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication.GetType().InvokeMember("ZoomExtents", BindingFlags.InvokeMethod, null, Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication, null);
                Database db = doc.Database;
                Editor   ed = doc.Editor;

                string dwgFileName =
                    Application.GetSystemVariable("DWGNAME") as string;
                string dwgPath =
                    Application.GetSystemVariable("DWGPREFIX") as string;

                string name =
                    System.IO.Path.GetFileNameWithoutExtension(dwgFileName);

                //find a temp location.
                string strTemp = System.IO.Path.GetTempPath();

                //PromptStringOptions options =
                //    new PromptStringOptions("Specific the DWF file name");
                //options.DefaultValue = "c:\\temp\\" + name + ".dwf";
                //PromptResult result = ed.GetString(options);

                //if (result.Status != PromptStatus.OK)
                //    return;

                //get the layout ObjectId List
                System.Collections.ArrayList layoutList = null;
                try
                {
                    layoutList = layouts;
                }
                catch
                {
                    //  Application.ShowAlertDialog("Unable to get layouts name");
                    return;
                }

                Publisher publisher = Application.Publisher;

                //put the plot in foreground
                short bgPlot =
                    (short)Application.GetSystemVariable("BACKGROUNDPLOT");

                Application.SetSystemVariable("BACKGROUNDPLOT", 0);

                using (Transaction tr =
                           db.TransactionManager.StartTransaction())
                {
                    DsdEntryCollection collection =
                        new DsdEntryCollection();

                    Layout _layout = null;
                    foreach (ObjectId layoutId in layoutList)
                    {
                        Layout layout = tr.GetObject(layoutId, OpenMode.ForWrite) as Layout;

                        #region plot Extends

                        Point3d pMin = layout.Extents.MinPoint;
                        Point3d pMax = layout.Extents.MaxPoint;
                        PlotSettingsValidator psv = PlotSettingsValidator.Current;
                        PlotSettings          ps  = new PlotSettings(layout.ModelType);
                        ps.CopyFrom(layout);
                        psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
                        bool bAreaIsLandscape = true;
                        if (layout.ModelType)
                        {
                            bAreaIsLandscape = (db.Extmax.X - db.Extmin.X) > (db.Extmax.Y - db.Extmin.Y) ? true : false;
                        }
                        else
                        {
                            bAreaIsLandscape = (layout.Extents.MaxPoint.X - layout.Extents.MinPoint.X) > (layout.Extents.MaxPoint.Y - layout.Extents.MinPoint.Y) ? true : false;
                        }

                        bool bPaperIsLandscape = (ps.PlotPaperSize.X > ps.PlotPaperSize.Y) ? true : false;
                        if (bPaperIsLandscape != bAreaIsLandscape)
                        {
                            psv.SetPlotRotation(ps, PlotRotation.Degrees270);
                        }
                        ps.PlotSettingsName = layout.LayoutName + "_plot";
                        ps.AddToPlotSettingsDictionary(db);
                        tr.AddNewlyCreatedDBObject(ps, true);
                        psv.RefreshLists(ps);
                        layout.CopyFrom(ps);

                        #endregion

                        DsdEntry entry = new DsdEntry();

                        entry.DwgName = dwgPath + dwgFileName;
                        entry.Layout  = layout.LayoutName;
                        entry.Title   = Path.GetFileNameWithoutExtension(this.dwgFile) + "-" + layerName + "-" + layout.LayoutName;
                        entry.Nps     = ps.PlotSettingsName;// "AA";
                        _layout       = layout;
                        collection.Add(entry);
                    }

                    DsdData dsdData = new DsdData();

                    dsdData.SheetType       = SheetType.SinglePdf;
                    dsdData.ProjectPath     = pdfLocation;
                    dsdData.DestinationName = pdfLocation + name + " " + layerName + ".pdf";


                    dsdData.SetUnrecognizedData("PwdProtectPublishedDWF", "FALSE");
                    dsdData.SetUnrecognizedData("PromptForPwd", "FALSE");
                    dsdData.SetUnrecognizedData("INCLUDELAYER", "FALSE");
                    dsdData.NoOfCopies    = 1;
                    dsdData.IsHomogeneous = false;

                    string dsdFile = pdfLocation + name + layerName + ".dsd";

                    if (System.IO.File.Exists(dsdFile))
                    {
                        System.IO.File.Delete(dsdFile);
                    }

                    dsdData.SetDsdEntryCollection(collection);
                    dsdData.PromptForDwfName = false;

                    //Workaround to avoid promp for dwf file name
                    //set PromptForDwfName=FALSE in
                    //dsdData using StreamReader/StreamWriter
                    dsdData.WriteDsd(dsdFile);

                    StreamReader sr  = new StreamReader(dsdFile);
                    string       str = sr.ReadToEnd();
                    sr.Close();

                    //str =
                    //    str.Replace("PromptForDwfName=TRUE",
                    //                    "PromptForDwfName=FALSE");
                    str =
                        str.Replace("IncludeLayer=TRUE",
                                    "IncludeLayer=FALSE");

                    StreamWriter sw = new StreamWriter(dsdFile);
                    sw.Write(str);
                    sw.Close();

                    dsdData.ReadDsd(dsdFile);

                    //18-07-2018
                    //PlotSettings ps = new PlotSettings(_layout.ModelType);
                    //ps.CopyFrom(_layout);

                    //PlotSettingsValidator psv = PlotSettingsValidator.Current;
                    //psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
                    //psv.SetUseStandardScale(ps, true);
                    //psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
                    //psv.SetPlotCentered(ps, true);


                    //// We'll use the standard DWF PC3, as

                    //// for today we're just plotting to file


                    //psv.SetPlotConfigurationName(ps, "DWG to PDF.PC3", "ANSI_A_(8.50_x_11.00_Inches)");

                    using (PlotConfig pc = PlotConfigManager.SetCurrentConfig("DWG to PDF.PC3"))
                    {
                        publisher.PublishExecute(dsdData, pc);
                    }

                    System.IO.File.Delete(dsdFile);

                    tr.Commit();
                }

                //reset the background plot value
                Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot);
            }
Example #14
0
        public static 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);
        }
Example #15
0
        public void PublisherDSD(DsdEntryCollection collection)
        {
            try
            {
                Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("BACKGROUNDPLOT", 0);
                DsdData dsd = new DsdData();

                dsd.SetDsdEntryCollection(collection);

                //dsd.ProjectPath = dirOutput;
                dsd.LogFilePath = Path.Combine(dir, "logPlotPdf.log");
                dsd.SheetType = SheetType.MultiPdf;
                dsd.IsSheetSet = true;
                dsd.NoOfCopies = 1;
                dsd.DestinationName = Path.Combine(dir, filePdfOutputName);
                dsd.SheetSetName = "PublisherSet";
                dsd.PromptForDwfName = false;
                string dsdFile = Path.Combine(dir, "PublisherDsd.dsd");
                dsd.WriteDsd(dsdFile);

                int nbSheets = collection.Count;

                using (PlotProgressDialog progressDlg = new PlotProgressDialog(false, nbSheets, true))
                {
                    progressDlg.set_PlotMsgString(PlotMessageIndex.DialogTitle, title);
                    progressDlg.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Отмена задания");
                    progressDlg.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "Отмена листа");
                    progressDlg.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, title);
                    progressDlg.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "Печать листа");

                    progressDlg.UpperPlotProgressRange = 100;
                    progressDlg.LowerPlotProgressRange = 0;

                    progressDlg.UpperSheetProgressRange = 100;
                    progressDlg.LowerSheetProgressRange = 0;

                    progressDlg.IsVisible = true;

                    Publisher publisher = Autodesk.AutoCAD.ApplicationServices.Application.Publisher;
                    PlotConfigManager.SetCurrentConfig("DWG To PDF.pc3");

                    //Application.Publisher.AboutToBeginPublishing += new Autodesk.AutoCAD.Publishing.AboutToBeginPublishingEventHandler(Publisher_AboutToBeginPublishing);

                    //Application.Publisher.PublishExecute(dsd, PlotConfigManager.CurrentConfig);

                    publisher.PublishDsd(dsdFile, progressDlg);
                    publisher.BeginSheet += Publisher_BeginSheet;

                }
                File.Delete(dsdFile);
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
Example #16
0
        static public void BatchPublish(System.Collections.Generic.List <string> docsToPlot)
        {
            DsdEntryCollection collection = new DsdEntryCollection();
            Document           doc        = Application.DocumentManager.MdiActiveDocument;

            foreach (string filename in docsToPlot)
            {
                using (DocumentLock doclock = doc.LockDocument())
                {
                    Database db = new Database(false, true);
                    db.ReadDwgFile(
                        filename, System.IO.FileShare.Read, true, "");
                    System.IO.FileInfo fi      = new System.IO.FileInfo(filename);
                    string             docName =
                        fi.Name.Substring(0, fi.Name.Length - 4);
                    using (Transaction Tx =
                               db.TransactionManager.StartTransaction())
                    {
                        foreach (ObjectId layoutId in getLayoutIds(db))
                        {
                            Layout layout = Tx.GetObject(layoutId, OpenMode.ForRead) as Layout;

                            DsdEntry entry = new DsdEntry
                            {
                                DwgName = filename,
                                Layout  = layout.LayoutName,
                                Title   = docName + "_" + layout.LayoutName
                            };
                            entry.NpsSourceDwg = entry.DwgName;
                            entry.Nps          = "Setup1";
                            collection.Add(entry);
                        }
                        Tx.Commit();
                    }
                }
            }
            DsdData dsdData = new DsdData();

            dsdData.SheetType   = SheetType.MultiPdf;
            dsdData.ProjectPath = @"C:\Users\yusufzhon.marasulov\Desktop\test";
            //Not used for "SheetType.SingleDwf"
            //dsdData.DestinationName = dsdData.ProjectPath + "\\output.dwf";
            dsdData.SetDsdEntryCollection(collection);
            string dsdFile = dsdData.ProjectPath + "\\dsdData.dsd";

            //Workaround to avoid promp for dwf file name
            //set PromptForDwfName=FALSE in dsdData
            //using StreamReader/StreamWriter
            if (System.IO.File.Exists(dsdFile))
            {
                System.IO.File.Delete(dsdFile);
            }
            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");
            System.IO.StreamWriter sw = new System.IO.StreamWriter(dsdFile);
            sw.Write(str);
            sw.Close();
            dsdData.ReadDsd(dsdFile);
            System.IO.File.Delete(dsdFile);
            PlotConfig plotConfig =
                Autodesk.AutoCAD.PlottingServices.PlotConfigManager.SetCurrentConfig("DWG_To_PDF_Uzle.pc3");

            Autodesk.AutoCAD.Publishing.Publisher publisher =
                Autodesk.AutoCAD.ApplicationServices.Application.Publisher;
            publisher.PublishExecute(dsdData, plotConfig);
        }
Example #17
0
        static public void PublishAllLayouts()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            //put the plot in foreground
            short bgPlot = (short)Application.GetSystemVariable("BACKGROUNDPLOT");

            Application.SetSystemVariable("BACKGROUNDPLOT", 0);
            //get the layout ObjectId List
            List <ObjectId> layoutIds   = GetLayoutIds(db);
            string          dwgFileName = (string)Application.GetSystemVariable("DWGNAME");
            string          dwgPath     = (string)Application.GetSystemVariable("DWGPREFIX");

            using (Transaction Tx = db.TransactionManager.StartTransaction())
            {
                DsdEntryCollection collection = new DsdEntryCollection();
                foreach (ObjectId layoutId in layoutIds)
                {
                    Layout layout = Tx.GetObject(layoutId, OpenMode.ForRead)
                                    as Layout;
                    if (layout.LayoutName != "Model")
                    {
                        DsdEntry entry = new DsdEntry();
                        entry.DwgName      = dwgPath + dwgFileName;
                        entry.Layout       = layout.LayoutName;
                        entry.Title        = "Layout_" + layout.LayoutName;
                        entry.NpsSourceDwg = entry.DwgName;
                        entry.Nps          = "Setup1";

                        collection.Add(entry);
                    }

                    //TODO have to think about creating collection depend of block view
                }
                dwgFileName = dwgFileName.Substring(0, dwgFileName.Length - 4);
                DsdData dsdData = new DsdData();
                dsdData.SheetType       = SheetType.MultiPdf; //SheetType.MultiPdf
                dsdData.ProjectPath     = dwgPath;
                dsdData.DestinationName =
                    $"{dsdData.ProjectPath}{dwgFileName}.pdf";
                if (System.IO.File.Exists(dsdData.DestinationName))
                {
                    System.IO.File.Delete(dsdData.DestinationName);
                }
                dsdData.SetDsdEntryCollection(collection);
                string dsdFile = $"{dsdData.ProjectPath}{dwgFileName}.dsd";
                //Workaround to avoid promp for dwf file name
                //set PromptForDwfName=FALSE in dsdData using
                //StreamReader/StreamWriter
                dsdData.WriteDsd(dsdFile);
                //System.IO.StreamReader sr =
                //    new System.IO.StreamReader(dsdFile, Encoding.Default);
                //string str = sr.ReadToEnd();
                //sr.Close();
                //str = str.Replace(
                //    "PromptForDwfName=TRUE", "PromptForDwfName=FALSE");
                //System.IO.StreamWriter sw =
                //    new System.IO.StreamWriter(dsdFile, true, Encoding.Default);
                //sw.Write(str);
                //sw.Close();
                dsdData.ReadDsd(dsdFile);

                System.IO.File.Delete(dsdFile);
                PlotConfig plotConfig =
                    Autodesk.AutoCAD.PlottingServices.PlotConfigManager.SetCurrentConfig("DWG_To_PDF_Uzle.pc3");
                //PlotConfig pc = Autodesk.AutoCAD.PlottingServices.
                //  PlotConfigManager.SetCurrentConfig("DWG To PDF.pc3");
                Autodesk.AutoCAD.Publishing.Publisher publisher =
                    Autodesk.AutoCAD.ApplicationServices.Application.Publisher;
                publisher.AboutToBeginPublishing +=
                    new Autodesk.AutoCAD.Publishing.
                    AboutToBeginPublishingEventHandler(
                        Publisher_AboutToBeginPublishing);
                dsdData.PromptForDwfName = false;
                publisher.PublishExecute(dsdData, plotConfig);
                Tx.Commit();
            }
            //reset the background plot value
            Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot);
        }
Example #18
0
        /// <summary>
        /// The BatchPublish.
        /// </summary>
        /// <param name="docsToPlot">The docsToPlot<see cref="List{string}"/>.</param>
        private static void BatchPublish(List <string> docsToPlot)
        {
            using (DsdEntryCollection collection = new DsdEntryCollection())
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                foreach (string filename in docsToPlot)
                {
                    using (DocumentLock doclock = doc.LockDocument())
                    {
                        using (Database db = new Database(false, true))
                        {
                            db.ReadDwgFile(filename, System.IO.FileShare.Read, true, "");
                            System.IO.FileInfo fi      = new FileInfo(filename);
                            string             docName = fi.Name.Substring(0, fi.Name.Length - 4);
                            using (Transaction Tx = db.TransactionManager.StartTransaction())
                            {
                                foreach (ObjectId layoutId in GeLayoutIds(db))
                                {
                                    Layout layout = Tx.GetObject(layoutId, OpenMode.ForRead) as Layout;
                                    if (!layout.ModelType)
                                    {
                                        var ids = layout.GetViewports();
                                        if (ids.Count == 0)
                                        {
                                            doc.Editor.WriteMessage($"\n{layout.LayoutName} is not initialized, so no plottable sheets in the current drawing ");
                                        }
                                    }

                                    DsdEntry entry = new DsdEntry
                                    {
                                        DwgName = filename,
                                        Layout  = layout.LayoutName,
                                        Title   = docName + "_" + layout.LayoutName
                                    };
                                    entry.NpsSourceDwg = entry.DwgName;
                                    entry.Nps          = "Setup1";
                                    collection.Add(entry);
                                }
                                Tx.Commit();
                            }
                        }
                    }
                }
                using (DsdData dsdData = new DsdData())
                {
                    dsdData.SheetType   = SheetType.MultiPdf;
                    dsdData.ProjectPath = rootDir;
                    dsdData.SetDsdEntryCollection(collection);
                    string dsdFile = dsdData.ProjectPath + "\\dsdData.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");
                    string strToApped = "[PublishOptions]\nInitLayouts = TRUE";
                    str += strToApped;
                    System.IO.StreamWriter sw = new System.IO.StreamWriter(dsdFile);
                    sw.Write(str);
                    sw.Close();
                    dsdData.ReadDsd(dsdFile);
                    System.IO.File.Delete(dsdFile);
                    PlotConfig plotConfig = Autodesk.AutoCAD.PlottingServices.PlotConfigManager.SetCurrentConfig("DWG To PDF.pc3");
                    Autodesk.AutoCAD.Publishing.Publisher publisher = Autodesk.AutoCAD.ApplicationServices.Core.Application.Publisher;
                    try
                    {
                        publisher.PublishExecute(dsdData, plotConfig);
                    }
                    catch (Exception ex) {
                        doc.Editor.WriteMessage($"Exeception: {ex.StackTrace}");
                    }
                }
            }


            //This is hack to prevent from not finding result.pdf
            foreach (var file in Directory.GetFiles(rootDir, "*.pdf"))
            {
                System.IO.FileInfo fi = new System.IO.FileInfo(file);
                // Check if file is there
                if (fi.Exists)
                {
                    // Move file with a new name. Hence renamed.
                    fi.MoveTo(Path.Combine(Directory.GetCurrentDirectory(), "result.pdf"));
                    break;
                }
            }
        }
Example #19
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);
        }
Example #20
0
        private void PlotFiles()
        {
            using (var dsdCol = new DsdEntryCollection())
            {
                var indexfile = 0;

                title = $"Печать {filesDwg.Length} файлов dwg...";

                foreach (var fileDwg in filesDwg)
                {
                    if (HostApplicationServices.Current.UserBreak())
                    {
                        throw new OperationCanceledException();
                    }
                    indexfile++;
                    using (var dbTemp = new Database(false, true))
                    {
                        dbTemp.ReadDwgFile(fileDwg, FileOpenMode.OpenForReadAndAllShare, false, string.Empty);
                        dbTemp.CloseInput(true);
                        using (var t = dbTemp.TransactionManager.StartTransaction())
                        {
                            var layouts = dbTemp.GetLayouts();

                            // Фильтр листов
                            if (Options.FilterState)
                            {
                                layouts = FilterLayouts(layouts, Options);
                            }

                            var layoutsDsd = new List <Tuple <Layout, DsdEntry> >();
                            foreach (var layout in layouts)
                            {
                                var dsdEntry = new DsdEntry()
                                {
                                    Layout       = layout.LayoutName,
                                    DwgName      = fileDwg,
                                    NpsSourceDwg = fileDwg,
                                    Title        = indexfile + "-" + layout.LayoutName
                                };
                                layoutsDsd.Add(new Tuple <Layout, DsdEntry>(layout, dsdEntry));
                            }

                            if (Options.SortTabOrName)
                            {
                                layoutsDsd.Sort((l1, l2) => l1.Item1.TabOrder.CompareTo(l2.Item1.TabOrder));
                            }
                            else
                            {
                                layoutsDsd.Sort((l1, l2) =>
                                                string.Compare(l1.Item1.LayoutName, l2.Item1.LayoutName, StringComparison.Ordinal));
                            }

                            layoutsDsd.ForEach(l => dsdCol.Add(l.Item2));
                            t.Commit();
                        }
                    }
                }

                PublisherDSD(dsdCol);
            }
        }
Example #21
0
        public void PublisherDSD(DsdEntryCollection collection)
        {
            try
            {
                var dsdFile = Path.Combine(dir, filePdfOutputName + ".dsd");
                if (!filePdfOutputName.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase))
                {
                    filePdfOutputName += ".pdf";
                }
                var destFile = Path.Combine(dir, filePdfOutputName);
                CheckFileAccess(destFile);
                Application.SetSystemVariable("BACKGROUNDPLOT", 0);
                using (var dsd = new DsdData())
                {
                    if (PikSettings.UserGroup == "ДО")
                    {
                        dsd.PlotStampOn = true;
                        dsd.ProjectPath = dir;
                    }

                    dsd.SetDsdEntryCollection(collection);
                    dsd.LogFilePath      = Path.Combine(dir, "logPlotPdf.log");
                    dsd.SheetType        = SheetType.MultiPdf;
                    dsd.IsSheetSet       = true;
                    dsd.NoOfCopies       = 1;
                    dsd.IsHomogeneous    = false;
                    dsd.DestinationName  = destFile;
                    dsd.SheetSetName     = "PublisherSet";
                    dsd.PromptForDwfName = false;
                    PostProcessDSD(dsd, dsdFile);
                }

                var nbSheets = collection.Count;
                using (var progressDlg = new PlotProgressDialog(false, nbSheets, true))
                {
                    progressDlg.set_PlotMsgString(PlotMessageIndex.DialogTitle, title);
                    progressDlg.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Отмена задания");
                    progressDlg.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "Отмена листа");
                    progressDlg.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, title);
                    progressDlg.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "Печать листа");
                    progressDlg.UpperPlotProgressRange  = 100;
                    progressDlg.LowerPlotProgressRange  = 0;
                    progressDlg.UpperSheetProgressRange = 100;
                    progressDlg.LowerSheetProgressRange = 0;
                    progressDlg.IsVisible = true;
                    var publisher = Application.Publisher;
                    PlotConfigManager.SetCurrentConfig("clk-PDF.pc3");
                    publisher.PublishDsd(dsdFile, progressDlg);
                    progressDlg.Destroy();
                }

                NetLib.IO.Path.TryDeleteFile(dsdFile);

                // Добавить бланк
                if (Options.BlankOn)
                {
                    var tempPdf = NetLib.IO.Path.GetTempFile(".pdf");
                    try
                    {
                        var blank = IO.Path.GetLocalSettingsFile(@"Support\blank.pdf");
                        new PdfEditor().AddSheet(filePdfOutputName, blank, 1, Options.BlankPageNumber, tempPdf);
                        while (true)
                        {
                            try
                            {
                                File.Copy(tempPdf, filePdfOutputName, true);
                                Process.Start(filePdfOutputName);
                                break;
                            }
                            catch
                            {
                                var res = MessageBox.Show($"Закройте pdf файл - {filePdfOutputName}",
                                                          "Ошибка добавление бланка", MessageBoxButtons.OKCancel);
                                if (res != DialogResult.OK)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    finally
                    {
                        NetLib.IO.Path.TryDeleteFile(tempPdf);
                    }
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #22
0
        static public void PublisherDSD()
        {
            try
            {
                DsdEntryCollection collection = new DsdEntryCollection();
                DsdEntry           entry;

                entry         = new DsdEntry();
                entry.Layout  = "Layout1";
                entry.DwgName = "c:\\Temp\\Drawing1.dwg";
                entry.Nps     = "Setup1";
                entry.Title   = "Sheet1";
                collection.Add(entry);

                entry         = new DsdEntry();
                entry.Layout  = "Layout1";
                entry.DwgName = "c:\\Temp\\Drawing2.dwg";
                entry.Nps     = "Setup1";
                entry.Title   = "Sheet2";
                collection.Add(entry);

                DsdData dsd = new DsdData();

                dsd.SetDsdEntryCollection(collection);

                dsd.ProjectPath     = "c:\\Temp\\";
                dsd.LogFilePath     = "c:\\Temp\\logdwf.log";
                dsd.SheetType       = SheetType.MultiDwf;
                dsd.NoOfCopies      = 1;
                dsd.DestinationName = "c:\\Temp\\PublisherTest.dwf";
                dsd.SheetSetName    = "PublisherSet";
                dsd.WriteDsd("c:\\Temp\\publisher.dsd");


                int nbSheets = collection.Count;

                using (PlotProgressDialog progressDlg =
                           new PlotProgressDialog(false, nbSheets, true))
                {
                    progressDlg.set_PlotMsgString(
                        PlotMessageIndex.DialogTitle,
                        "Plot API Progress");
                    progressDlg.set_PlotMsgString(
                        PlotMessageIndex.CancelJobButtonMessage,
                        "Cancel Job");
                    progressDlg.set_PlotMsgString(
                        PlotMessageIndex.CancelSheetButtonMessage,
                        "Cancel Sheet");
                    progressDlg.set_PlotMsgString(
                        PlotMessageIndex.SheetSetProgressCaption,
                        "Job Progress");
                    progressDlg.set_PlotMsgString(
                        PlotMessageIndex.SheetProgressCaption,
                        "Sheet Progress");

                    progressDlg.UpperPlotProgressRange = 100;
                    progressDlg.LowerPlotProgressRange = 0;

                    progressDlg.UpperSheetProgressRange = 100;
                    progressDlg.LowerSheetProgressRange = 0;

                    progressDlg.IsVisible = true;

                    Autodesk.AutoCAD.Publishing.Publisher publisher =
                        Application.Publisher;

                    Autodesk.AutoCAD.PlottingServices.PlotConfigManager.
                    SetCurrentConfig("DWF6 ePlot.pc3");

                    publisher.PublishDsd(
                        "c:\\Temp\\publisher.dsd", progressDlg);
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                PGA.MessengerManager.MessengerManager.AddLog(ex.Message);
            }
        }
Example #23
0
        public static void PublishViews2MultiSheet()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db  = doc.Database;
            var ed  = doc.Editor;

            var viewsToPlot = new StringCollection();

            viewsToPlot.Add("Test1");
            viewsToPlot.Add("Test2");
            viewsToPlot.Add("Current");
            // Create page setup based on the views
            using (var Tx = db.TransactionManager.StartTransaction())
            {
                var layoutId = LayoutManager.Current.GetLayoutId
                                   (LayoutManager.Current.CurrentLayout);

                var layout
                    = Tx.GetObject(layoutId, OpenMode.ForWrite) as Layout;

                foreach (var viewName in viewsToPlot)
                {
                    var plotSettings
                        = new PlotSettings(layout.ModelType);
                    plotSettings.CopyFrom(layout);

                    var 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,
                        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();
            }

            //put the plot in foreground
            var bgPlot = (short)Application.GetSystemVariable("BACKGROUNDPLOT");

            Application.SetSystemVariable("BACKGROUNDPLOT", 0);

            var dwgFileName
                = Application.GetSystemVariable("DWGNAME") as string;
            var dwgPath
                = Application.GetSystemVariable("DWGPREFIX") as string;

            using (var Tx = db.TransactionManager.StartTransaction())
            {
                var collection = new DsdEntryCollection();
                var activeLayoutId
                    = LayoutManager.Current.GetLayoutId
                          (LayoutManager.Current.CurrentLayout);

                foreach (var viewName in viewsToPlot)
                {
                    var layout = Tx.GetObject(
                        activeLayoutId,
                        OpenMode.ForRead
                        ) as Layout;

                    var 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);
                }

                // remove the ".dwg" extension
                dwgFileName = dwgFileName.Substring(0, dwgFileName.Length - 4);

                var dsdData = new DsdData();

                dsdData.SheetType   = SheetType.MultiDwf;
                dsdData.ProjectPath = dwgPath;
                dsdData.DestinationName
                    = dsdData.ProjectPath + dwgFileName + ".dwf";

                if (File.Exists(dsdData.DestinationName))
                {
                    File.Delete(dsdData.DestinationName);
                }

                dsdData.SetDsdEntryCollection(collection);

                var dsdFile
                    = dsdData.ProjectPath + dwgFileName + ".dsd";

                //Workaround to avoid promp for pdf file name
                //set PromptForDwfName=FALSE in dsdData using StreamReader/StreamWriter

                dsdData.WriteDsd(dsdFile);

                var sr  = new StreamReader(dsdFile);
                var str = sr.ReadToEnd();
                sr.Close();

                // Replace PromptForDwfName
                str = str.Replace("PromptForDwfName=TRUE", "PromptForDwfName=FALSE");

                // Workaround to have the page setup names included in the DSD file
                // Replace Setup names based on the created page setups
                // May not be required if Nps is output to the DSD
                var occ        = 0;
                var index      = str.IndexOf("Setup=");
                var startIndex = 0;
                var dsdText    = new StringBuilder();
                while (index != -1)
                {
                    // 6 for length of "Setup="
                    var 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++;
                }

                // Write the DSD
                var sw
                    = new StreamWriter(dsdFile);
                sw.Write(dsdText.ToString());
                sw.Close();

                // Read the updated DSD file
                dsdData.ReadDsd(dsdFile);

                // Erase DSD as it is no longer needed
                File.Delete(dsdFile);

                var plotConfig
                    = PlotConfigManager.SetCurrentConfig("DWF6 ePlot.pc3");

                var publisher = Application.Publisher;

                // Publish it
                publisher.PublishExecute(dsdData, plotConfig);

                Tx.Commit();
            }

            //reset the background plot value
            Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot);
        }
Example #24
0
        public static void PublishLayouts(string path, string hole)
        {
            var completepath = Path.ChangeExtension(path, "pdf");

            var filename = Application.DocumentManager.MdiActiveDocument.Name;

            using (DsdEntryCollection dsdDwgFiles = new DsdEntryCollection())
            {
                // Define the first layout
                using (DsdEntry dsdDwgFile1 = new DsdEntry())
                {
                    // Set the file name and layout
                    dsdDwgFile1.DwgName = filename;
                    dsdDwgFile1.Layout  = "PGA-OUTPUT";
                    dsdDwgFile1.Title   = "PGA TOUR AUTOGENERATED SURFACE";

                    // Set the page setup override
                    dsdDwgFile1.Nps          = "";
                    dsdDwgFile1.NpsSourceDwg = "";

                    dsdDwgFiles.Add(dsdDwgFile1);
                }
                #region Define Second Layout

                //// Define the second layout
                //using (DsdEntry dsdDwgFile2 = new DsdEntry())
                //{
                //    // Set the file name and layout
                //    dsdDwgFile2.DwgName = "C:\\AutoCAD\\Samples\\Sheet Sets\\Architectural\\A-02.dwg";
                //    dsdDwgFile2.Layout = "ELEVATIONS";
                //    dsdDwgFile2.Title = "A-02 ELEVATIONS";

                //    // Set the page setup override
                //    dsdDwgFile2.Nps = "";
                //    dsdDwgFile2.NpsSourceDwg = "";

                //    dsdDwgFiles.Add(dsdDwgFile2);
                //}
                #endregion


                #region Define third layout
                //// Define the second layout
                using (DsdEntry dsdDwgFile2 = new DsdEntry())
                {
                    // Set the file name and layout
                    dsdDwgFile2.DwgName = filename;
                    dsdDwgFile2.Layout  = "ELEVATIONS";
                    dsdDwgFile2.Title   = "A-02 ELEVATIONS";


                    // Set the page setup override
                    dsdDwgFile2.Nps          = "";
                    dsdDwgFile2.NpsSourceDwg = @"C:\Users\m4800\AppData\Roaming\Autodesk\ApplicationPlugins\PGA-CivilTinSurf2016.bundle\Contents\Template\PGA_PRINT_TMPLT.dwg";
                    dsdDwgFiles.Add(dsdDwgFile2);
                }
                #endregion

                // Set the properties for the DSD file and then write it out
                using (DsdData dsdFileData = new DsdData())
                {
                    dsdFileData.PromptForDwfName = false;
                    // Set the target information for publishing
                    //dsdFileData.DestinationName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\PGA-Publish.pdf";
                    //dsdFileData.ProjectPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\";
                    dsdFileData.DestinationName = completepath;    //PGA-Publish.pdf;
                    dsdFileData.ProjectPath     = Path.GetDirectoryName(completepath);

                    dsdFileData.SheetType = SheetType.MultiPdf;

                    // Set the drawings that should be added to the publication
                    dsdFileData.SetDsdEntryCollection(dsdDwgFiles);

                    // Set the general publishing properties
                    //dsdFileData.LogFilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\myBatch.txt";
                    dsdFileData.LogFilePath = Path.ChangeExtension(path, "txt"); // "\\myBatch.txt";


                    // Create the DSD file
                    //dsdFileData.WriteDsd(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\batchdrawings2.dsd");
                    dsdFileData.WriteDsd(Path.ChangeExtension(path, "dsd")); //"\\batchdrawings2.dsd");
                    try
                    {
                        // Publish the specified drawing files in the DSD file, and
                        // honor the behavior of the BACKGROUNDPLOT system variable

                        using (DsdData dsdDataFile = new DsdData())
                        {
                            //dsdDataFile.ReadDsd(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\batchdrawings2.dsd");
                            dsdDataFile.ReadDsd(Path.ChangeExtension(path, "dsd")); // + "\\batchdrawings2.dsd");
                            // Get the DWG to PDF.pc3 and use it as a
                            // device override for all the layouts
                            PlotConfig acPlCfg = PlotConfigManager.SetCurrentConfig("DWG to PDF.PC3");

                            Application.Publisher.PublishExecute(dsdDataFile, acPlCfg);
                        }
                    }
                    catch (Autodesk.AutoCAD.Runtime.Exception es)
                    {
                        MessengerManager.MessengerManager.LogException(es);
                    }
                }
            }
        }