//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 #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
        // Creates the DSD file from a template (default options)
        private bool TryCreateDSD()
        {
            using (var dsd = new DsdData())
                using (var dsdEntries = CreateDsdEntryCollection(_layouts))
                {
                    if (dsdEntries.Count <= 0)
                    {
                        return(false);
                    }

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

                    sheetNum = dsdEntries.Count;
                    dsd.SetDsdEntryCollection(dsdEntries);
                    dsd.SetUnrecognizedData("PwdProtectPublishedDWF", "FALSE");
                    dsd.SetUnrecognizedData("PromptForPwd", "FALSE");
                    dsd.NoOfCopies      = 1;
                    dsd.DestinationName = outputFile;
                    dsd.IsHomogeneous   = false;
                    dsd.LogFilePath     = Path.Combine(outputDir, LOG);
                    PostProcessDSD(dsd);
                    return(true);
                }
        }
Example #4
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 #5
0
        public static void PrintToPdf()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;

            Editor ed = doc.Editor;

            Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Focus();

            object obj = Application.GetSystemVariable("DWGTITLED");

            string drawingName = Path.GetFileName(doc.Name);
            string drawingPath = doc.Name;

            if (System.Convert.ToInt16(obj) == 0)
            {
                drawingPath = "d:\\QuickPrint.dwg";
                drawingName = "QuickPrint.dwg";
            }

            doc.Database.SaveAs(drawingPath, true, DwgVersion.Current, doc.Database.SecurityParameters);

            DsdData dsd = new DsdData();


            DSDObject dsdObj = new DSDObject();

            dsdObj.DWG     = drawingPath;
            dsdObj.DwgName = drawingName;
            dsdObj.Layout  = "QuickView";

            using (StreamWriter writer = new StreamWriter("d:\\QuickPrint.dsd"))
            {
                writer.WriteLine("[DWF6Version]");
                writer.WriteLine("Ver=1");
                writer.WriteLine(dsdObj.CreateDSDEntry());
                writer.WriteLine("[Target]");
                writer.WriteLine("Type=6");
                writer.WriteLine("DWF=d:\\Autocad Prints\\QuickPrint.pdf");
                writer.WriteLine("OUT=d:\\");
                writer.WriteLine("PWD=");
            }

            FileInfo fi = new FileInfo("D:\\QuickPrint.dsd");

            if (fi.Length > 0)
            {
                Application.SetSystemVariable("FILEDIA", 0);
                Application.SetSystemVariable("BACKGROUNDPLOT", 0);
                doc.SendStringToExecute($"-publish {fi.FullName}\n", true, false, false);


                Application.Publisher.AboutToBeginPublishing      += Publisher_AboutToBeginPublishing;
                Application.Publisher.EndPublish                  += Publisher_EndPublish;
                Application.Publisher.CancelledOrFailedPublishing += Publisher_CancelledOrFailedPublishing;
            }
        }
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);
        }
Example #7
0
            // Writes the definitive DSD file from the templates and additional informations
            private void PostProcessDSD(DsdData dsd)
            {
                string str, newStr;
                string tmpFile = Path.Combine(this.outputDir, "temp.dsd");

                dsd.WriteDsd(tmpFile);


                using (StreamReader reader = new StreamReader(tmpFile, Encoding.Default))
                    using (StreamWriter writer = new StreamWriter(this.dsdFile, false, Encoding.Default))
                    {
                        while (!reader.EndOfStream)
                        {
                            str = reader.ReadLine();
                            if (str.Contains("Has3DDWF"))
                            {
                                newStr = "Has3DDWF=0";
                            }
                            else if (str.Contains("OriginalSheetPath"))
                            {
                                newStr = "OriginalSheetPath=" + this.dwgFile;
                            }
                            else if (str.Contains("Type"))
                            {
                                newStr = "Type=" + this.plotType;
                            }
                            else if (str.Contains("OUT"))
                            {
                                newStr = "OUT=" + this.outputDir;
                            }
                            else if (str.Contains("IncludeLayer"))
                            {
                                newStr = "IncludeLayer=FALSE";
                            }
                            else if (str.Contains("PromptForDwfName"))
                            {
                                newStr = "PromptForDwfName=FALSE";
                            }
                            else if (str.Contains("LogFilePath"))
                            {
                                newStr = "LogFilePath=" + Path.Combine(this.outputDir, LOG);
                            }
                            else
                            {
                                newStr = str;
                            }
                            writer.WriteLine(newStr);
                        }
                    }
                File.Delete(tmpFile);
            }
        private void PostProcessDSD(DsdData dsd)
        {
            string str, newStr;
             string tmpFile = Path.Combine(this.outputDir, "temp.dsd");

             dsd.WriteDsd(tmpFile);

             using (StreamReader reader = new StreamReader(tmpFile, Encoding.Default))
             using (StreamWriter writer = new StreamWriter(this.dsdFile, false, Encoding.Default))
             {
            while (!reader.EndOfStream)
            {
               str = reader.ReadLine();
               if (str.Contains("Has3DDWF"))
               {
                  newStr = "Has3DDWF=0";
               }
               else if (str.Contains("OriginalSheetPath"))
               {
                  newStr = "OriginalSheetPath=" + this.dwgFile;
               }
               else if (str.Contains("Type"))
               {
                  newStr = "Type=6";
               }
               else if (str.Contains("OUT"))
               {
                  newStr = "OUT=" + this.outputDir;
               }
               else if (str.Contains("IncludeLayer"))
               {
                  newStr = "IncludeLayer=TRUE";
               }
               else if (str.Contains("PromptForDwfName"))
               {
                  newStr = "PromptForDwfName=FALSE";
               }
               else if (str.Contains("LogFilePath"))
               {
                  newStr = "LogFilePath=" + Path.Combine(this.outputDir, LOG);
               }
               else
               {
                  newStr = str;
               }
               writer.WriteLine(newStr);
            }
             }
             File.Delete(tmpFile);
        }
Example #9
0
        private void PostProcessDSD([NotNull] DsdData dsd, [NotNull] string destFile)
        {
            var tmpFile = Path.Combine(dir, "temp.dsd");

            dsd.WriteDsd(tmpFile);
            using (var reader = new StreamReader(tmpFile, Encoding.Default))
                using (var writer = new StreamWriter(destFile, false, Encoding.Default))
                {
                    var fileDwg = string.Empty;
                    while (!reader.EndOfStream)
                    {
                        var str = reader.ReadLine();
                        if (str == null)
                        {
                            continue;
                        }
                        string newStr;
                        if (str.StartsWith("Has3DDWF="))
                        {
                            newStr = "Has3DDWF=0";
                        }
                        else if (str.StartsWith("DWG=", StringComparison.OrdinalIgnoreCase))
                        {
                            fileDwg = str.Substring(4);
                            newStr  = str;
                        }
                        else if (str.StartsWith("OriginalSheetPath="))
                        {
                            newStr = "OriginalSheetPath=" + fileDwg;
                        }
                        else if (str.StartsWith("Type="))
                        {
                            newStr = "Type=6";
                        }
                        else if (str.StartsWith("PromptForDwfName="))
                        {
                            newStr = "PromptForDwfName=FALSE";
                        }
                        else
                        {
                            newStr = str;
                        }

                        writer.WriteLine(newStr);
                    }
                }

            File.Delete(tmpFile);
        }
Example #10
0
        Stream(ArrayList data, DsdData dsd)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(DsdData)));

            data.Add(new Snoop.Data.String("Category name", dsd.CategoryName));
            data.Add(new Snoop.Data.String("Destination name", dsd.DestinationName));
            data.Add(new Snoop.Data.Object("DWF 3D options", dsd.Dwf3dOptions));
            data.Add(new Snoop.Data.Bool("Is homogenous", dsd.IsHomogeneous));
            data.Add(new Snoop.Data.Bool("Is sheet set", dsd.IsSheetSet));
            data.Add(new Snoop.Data.String("Log file path", dsd.LogFilePath));
            data.Add(new Snoop.Data.Int("Major version", dsd.MajorVersion));
            data.Add(new Snoop.Data.Int("Minor version", dsd.MinorVersion));
            data.Add(new Snoop.Data.Int("Number of copies", dsd.NoOfCopies));
            data.Add(new Snoop.Data.String("Password", dsd.Password));
            data.Add(new Snoop.Data.String("Project path", dsd.ProjectPath));
            data.Add(new Snoop.Data.Bool("Plot stamp on", dsd.PlotStampOn));
            data.Add(new Snoop.Data.String("Selection set name", dsd.SelectionSetName));
            data.Add(new Snoop.Data.String("Sheet set name", dsd.SheetSetName));
            data.Add(new Snoop.Data.String("Sheet type", dsd.SheetType.ToString()));
            data.Add(new Snoop.Data.ObjectCollection("Unrecognized data section names", dsd.UnrecognizedDataSectionNames));
            data.Add(new Snoop.Data.ObjectCollection("Unrecognized data sections", dsd.UnrecognizedDataSections));
        }
Example #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
0
        CollectEvent(object sender, CollectorEventArgs e)
        {
            // cast the sender object to the SnoopCollector we are expecting
            Collector snoopCollector = sender as Collector;

            if (snoopCollector == null)
            {
                Debug.Assert(false);    // why did someone else send us the message?
                return;
            }

            // see if it is a type we are responsible for
            PlotLogger log = e.ObjToSnoop as PlotLogger;

            if (log != null)
            {
                Stream(snoopCollector.Data(), log);
                return;
            }

            DsdData dsdData = e.ObjToSnoop as DsdData;

            if (dsdData != null)
            {
                Stream(snoopCollector.Data(), dsdData);
                return;
            }

            DsdEntry dsdEntry = e.ObjToSnoop as DsdEntry;

            if (dsdEntry != null)
            {
                Stream(snoopCollector.Data(), dsdEntry);
                return;
            }

            Dwf3dOptions dwf3dOpt = e.ObjToSnoop as Dwf3dOptions;

            if (dwf3dOpt != null)
            {
                Stream(snoopCollector.Data(), dwf3dOpt);
                return;
            }

            BeginDocumentEventArgs beginDocArgs = e.ObjToSnoop as BeginDocumentEventArgs;

            if (beginDocArgs != null)
            {
                Stream(snoopCollector.Data(), beginDocArgs);
                return;
            }

            BeginPageEventArgs beginPageArgs = e.ObjToSnoop as BeginPageEventArgs;

            if (beginPageArgs != null)
            {
                Stream(snoopCollector.Data(), beginPageArgs);
                return;
            }

            BeginPlotEventArgs beginPlotArgs = e.ObjToSnoop as BeginPlotEventArgs;

            if (beginPlotArgs != null)
            {
                Stream(snoopCollector.Data(), beginPlotArgs);
                return;
            }

            EndDocumentEventArgs endDocArgs = e.ObjToSnoop as EndDocumentEventArgs;

            if (endDocArgs != null)
            {
                Stream(snoopCollector.Data(), endDocArgs);
                return;
            }

            EndPageEventArgs endPageArgs = e.ObjToSnoop as EndPageEventArgs;

            if (endPageArgs != null)
            {
                Stream(snoopCollector.Data(), endPageArgs);
                return;
            }

            EndPlotEventArgs endPlotArgs = e.ObjToSnoop as EndPlotEventArgs;

            if (endPlotArgs != null)
            {
                Stream(snoopCollector.Data(), endPlotArgs);
                return;
            }

            PlotInfo plotInfo = e.ObjToSnoop as PlotInfo;

            if (plotInfo != null)
            {
                Stream(snoopCollector.Data(), plotInfo);
                return;
            }

            PlotPageInfo plotPageInfo = e.ObjToSnoop as PlotPageInfo;

            if (plotPageInfo != null)
            {
                Stream(snoopCollector.Data(), plotPageInfo);
                return;
            }

            PlotConfig plotConfig = e.ObjToSnoop as PlotConfig;

            if (plotConfig != null)
            {
                Stream(snoopCollector.Data(), plotConfig);
                return;
            }

            PlotConfigInfo plotConfigInfo = e.ObjToSnoop as PlotConfigInfo;

            if (plotConfigInfo != null)
            {
                Stream(snoopCollector.Data(), plotConfigInfo);
                return;
            }

            PlotEngine plotEngine = e.ObjToSnoop as PlotEngine;

            if (plotEngine != null)
            {
                Stream(snoopCollector.Data(), plotEngine);
                return;
            }

            PlotInfoValidator plotInfoValidator = e.ObjToSnoop as PlotInfoValidator;

            if (plotInfoValidator != null)
            {
                Stream(snoopCollector.Data(), plotInfoValidator);
                return;
            }

            PlotProgress plotProgress = e.ObjToSnoop as PlotProgress;

            if (plotProgress != null)
            {
                Stream(snoopCollector.Data(), plotProgress);
                return;
            }

            // ValueTypes we have to treat a bit different
            if (e.ObjToSnoop is MediaBounds)
            {
                Stream(snoopCollector.Data(), (MediaBounds)e.ObjToSnoop);
                return;
            }
        }
Example #23
0
        // Writes the definitive DSD file from the templates and additional informations
        private void PostProcessDSD(DsdData dsd)
        {
            var tmpFile = Path.Combine(outputDir, "temp.dsd");

            try
            {
                dsd.WriteDsd(tmpFile);
                using (var reader = new StreamReader(tmpFile, Encoding.Default))
                    using (var writer = new StreamWriter(dsdFile, false, Encoding.Default))
                    {
                        while (!reader.EndOfStream)
                        {
                            var str = reader.ReadLine();
                            if (str == null)
                            {
                                continue;
                            }
                            string newStr;
                            if (str.Contains("Has3DDWF"))
                            {
                                newStr = "Has3DDWF=0";
                            }
                            else if (str.Contains("OriginalSheetPath"))
                            {
                                newStr = "OriginalSheetPath=" + dwgFile;
                            }
                            else if (str.Contains("Type"))
                            {
                                newStr = "Type=" + plotType;
                            }
                            else if (str.Contains("OUT"))
                            {
                                newStr = "OUT=" + outputDir;
                            }
                            else if (str.Contains("IncludeLayer"))
                            {
                                newStr = "IncludeLayer=TRUE";
                            }
                            else if (str.Contains("PromptForDwfName"))
                            {
                                newStr = "PromptForDwfName=FALSE";
                            }
                            else if (str.Contains("LogFilePath"))
                            {
                                newStr = "LogFilePath=" + Path.Combine(outputDir, LOG);
                            }
                            else
                            {
                                newStr = str;
                            }

                            writer.WriteLine(newStr);
                        }
                    }
            }
            catch
            {
                // ignored
            }

            File.Delete(tmpFile);
        }
Example #24
0
        // Creates the DSD file from a template (default options)
        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.sheetNum = dsdEntries.Count;

            dsd.SetDsdEntryCollection(dsdEntries);

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

            postProcessDSD(dsd);

            return true;
             }
        }
Example #25
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);
                    }
                }
            }
        }