Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // Start an AutoCAD instance
            AcadApplication acad = new AcadApplication();
            Console.WriteLine("AutoCAD started!");

            //Open an AxDbDocument
            object obj = acad.GetInterfaceObject("ObjectDBX.AxDbDocument.22"); //Acad2018
            AxDbDocument doc = obj as AxDbDocument;
                        
            if (doc == null)
            {
                Console.WriteLine("Cannot open AxDbDocument for some reason!");
                return;
            }
            else
            {
                doc.Open(@"a:\Dropbox\Infratools\2_Presentation\4.0 Automation\Dictionary\test.dwg");
                List<string> dicts = AcDictToList(doc.Database);
                Console.WriteLine(dicts.Count + " Dictionaries found.");
                foreach (string s in dicts)
                    Console.WriteLine(s);

            }
            //Get drawing information
            //Console.WriteLine("Entities in ModelSpace: " + doc.ModelSpace.Count);

            //You can make changes to the entities in AxDbDocument and save the changes back to the drawing file.

            //doc.Save();

            doc = null;
            acad.Quit();
            Console.Read();
        }
Exemplo n.º 2
0
 static bool QuitAutoCAD()
 {
     try
     {
         AcadApp.Quit();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 3
0
        // This version of Dispose gets called by our

        // destructor.

        protected virtual void Dispose(bool disposing)
        {
            // If we created our AutoCAD instance, call its

            // Quit method to avoid leaking memory.

            try
            {
                if (!_disposed && _initialized)
                {
                    _application.Quit();
                }
            }
            catch
            { }


            _disposed = true;
        }
Exemplo n.º 4
0
        public void Edit()
        {
            try
            {
                string serverIP   = CIni.ReadINI("updateconfig", "ServerIP");
                int    serverPort = int.Parse(CIni.ReadINI("updateconfig", "ServerPort"));
                if (VersionHelper.HasNewVersion(serverIP, serverPort))
                {
                    if (MessageBox.Show("服务器端发布了更新,请退出AutoCAD然后运行获取更新程序", "提示",
                                        MessageBoxButtons.OKCancel
                                        , MessageBoxIcon.Warning) == DialogResult.OK)
                    {
                        AcadApplication AcadApp = (AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
                        AcadApp.Quit();

                        return;
                    }
                }
            }
            finally
            {
                CADObjectEditCtrl pCADObjectEditCtrl = new CADObjectEditCtrl();

                Autodesk.AutoCAD.Windows.PaletteSet ps = new Autodesk.AutoCAD.Windows.PaletteSet("管网管理");

                ps.Style = PaletteSetStyles.ShowTabForSingle;
                ps.Style = PaletteSetStyles.NameEditable;
                ps.Style = PaletteSetStyles.ShowPropertiesMenu;
                ps.Style = PaletteSetStyles.ShowAutoHideButton;
                ps.Style = PaletteSetStyles.ShowCloseButton;

                ps.Dock        = DockSides.Left;
                ps.Visible     = true;
                ps.MinimumSize = new System.Drawing.Size(556, 490);
                ps.Size        = new System.Drawing.Size(556, 490);

                AcadApplication AcadApp = (AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
                Autodesk.AutoCAD.Interop.AcadDocument AcadDoc = AcadApp.ActiveDocument;
                string CurCadfile = AcadDoc.FullName;
                string CurMdbName = System.IO.Path.GetDirectoryName(CurCadfile) + "\\" + System.IO.Path.GetFileNameWithoutExtension(CurCadfile) + ".db";
                //MessageBox.Show(CurMdbName);
                if (!System.IO.File.Exists(CurMdbName))
                {
                    System.Windows.Forms.OpenFileDialog pDlg = new System.Windows.Forms.OpenFileDialog();
                    pDlg.Filter      = "数据库文件|*.db|所有文件(*.*)|*.*";
                    pDlg.Multiselect = false;
                    if (pDlg.ShowDialog() == DialogResult.OK)
                    {
                        SysDBUnitiy.MDBPath = pDlg.FileName;
                        ps.Add("管网管理", pCADObjectEditCtrl);
                        ps.Activate(0);
                    }
                }
                else
                {
                    SysDBUnitiy.MDBPath = CurMdbName;

                    ps.Add("管网管理", pCADObjectEditCtrl);
                    ps.Activate(0);
                }
            }
        }
Exemplo n.º 5
0
        public void exprotCAD(string o_cadFile, string file)
        {
            if (o_cadFile == null)
            {
                MessageBox.Show("请先读取CAD文件");
                return;
            }

            object filepath = file;

            Teigha.Runtime.Services trs = new Services();

            Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
            wordApp = new Microsoft.Office.Interop.Word.Application();
            wordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone;

            Document doc = null;

            doc = wordApp.Documents.Open(ref filepath, ref miss, ref miss, ref miss
                                         , ref miss, ref miss, ref miss, ref miss, ref miss
                                         , ref miss, ref miss, ref miss, ref miss);
            //搜索书签
            Boolean find = false;

            foreach (Microsoft.Office.Interop.Word.Bookmark bm in doc.Bookmarks)
            {
                if (bm.Name == "cad")
                {
                    find = true;
                }
            }
            if (!find)
            {
                MessageBox.Show("模板有误,请选择正确的模板");
                return;
            }
            if (!File.Exists(o_cadFile))
            {
                return;
            }
            Database db = new Database(false, true);                                           //CAD Database,CAD数据库

            db.ReadDwgFile((string)o_cadFile, FileOpenMode.OpenForReadAndAllShare, false, ""); //读取文件
            if (db == null)
            {
                return;
            }
            double x0 = 0, x1 = 0, y0 = 0, y1 = 0;
            bool   isIni = false;

            using (Transaction ts = db.TransactionManager.StartTransaction())                           //打开事务
            {
                BlockTableRecord btr = (BlockTableRecord)db.CurrentSpaceId.GetObject(OpenMode.ForRead); //块表记录
                foreach (var id in btr)                                                                 //遍历所有Entity
                {
                    Entity ent = (Entity)id.GetObject(OpenMode.ForRead);
                    if (isIni == false)
                    {
                        x0    = ent.GeometricExtents.MinPoint.X;
                        x1    = ent.GeometricExtents.MaxPoint.X;
                        y0    = ent.GeometricExtents.MinPoint.Y;
                        y1    = ent.GeometricExtents.MaxPoint.Y;
                        isIni = true;
                    }
                    else
                    {
                        try
                        {
                            if (x0 > ent.GeometricExtents.MinPoint.X)
                            {
                                x0 = ent.GeometricExtents.MinPoint.X;
                            }
                            if (x1 < ent.GeometricExtents.MaxPoint.X)
                            {
                                x1 = ent.GeometricExtents.MaxPoint.X;
                            }
                            if (y0 > ent.GeometricExtents.MinPoint.Y)
                            {
                                y0 = ent.GeometricExtents.MinPoint.Y;
                            }
                            if (y1 < ent.GeometricExtents.MaxPoint.Y)
                            {
                                y1 = ent.GeometricExtents.MaxPoint.Y;
                            }
                        }
                        catch { }
                    }
                }
                ViewportTableRecord vp = (ViewportTableRecord)Aux.active_viewport_id(db).GetObject(OpenMode.ForWrite);//视口表记录
                vp.CenterPoint = new Point2d((x0 + x1) / 2, (y0 + y1) / 2);

                vp.Width  = x1 - x0;
                vp.Height = y1 - y0;//稍微增大,以免地下有线没有被完全显示,到时候最好用比例
                ts.Commit();
            }
            db.SaveAs((string)o_cadFile, DwgVersion.Current);
            const string    progID = "AutoCAD.Application.18.0";
            AcadApplication acApp  = null;

            try
            {
                acApp = (AcadApplication)Marshal.GetActiveObject(progID);
            }
            catch
            {
                try
                {
                    Type acType = Type.GetTypeFromProgID(progID);
                    acApp = (AcadApplication)Activator.CreateInstance(acType, true);
                }
                catch
                {
                }
            }
            if (acApp != null)
            {
                acApp.Height = 500 + 55;
                acApp.Width  = (int)(500 * (x1 - x0) / (y1 - y0));
                acApp.Quit();
            }
            object link    = false;
            object cadFile = (object)o_cadFile;

            wordApp.Selection.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            object oStart = "cad";
            object range  = (object)doc.Bookmarks.get_Item(ref oStart).Range;

            try
            {
                InlineShape cadShape = wordApp.Selection.InlineShapes.AddOLEObject(ref miss, ref cadFile, ref link, ref link, ref miss
                                                                                   , ref miss, ref miss, ref range);

                cadShape.Width  = (float)(200 * (x1 - x0) / (y1 - y0));
                cadShape.Height = 200f;
            }
            catch { }

            doc.Save();
            doc.Close();
            wordApp.Quit();
            trs.Dispose();
            MessageBox.Show("导出成功");
        }
        static int Main(string[] args)
        {
            Options commandLineOptions = new Options();
            bool    parseErrorsOccured = false;

            CommandLine.Parser.Default.ParseArguments <Options>(args)
            .WithParsed <Options>(opts => commandLineOptions      = opts)
            .WithNotParsed <Options>((errs) => parseErrorsOccured = true);

            if (parseErrorsOccured)
            {
                //Console.WriteLine("some parse errors occured. ahoy.");
                return(1);
            }



            //*****parse the command-line arguments*****
            //for now, I will simply hard code these values.
            String nameOfSheetsetFile            = commandLineOptions.SheetSetFile;
            String nameOfPdfOutputFile           = commandLineOptions.OutputPdfFile;
            String baseName                      = System.IO.Path.GetTempFileName();
            String nameOfTheTemporaryDsdFile     = baseName + ".dsd";
            String nameOfTheTemporaryPlotLogFile = baseName + "-plot" + ".log";

            //TO DO: parse and verify the real command-line arguments, compose a help message.

            //*****read the sheetset file and construct a dsd file accordingly*****
            IAcSmSheetSetMgr sheetSetMgr;
            IAcSmDatabase    sheetdb;
            IAcSmSheetSet    sheetSet;

            Console.WriteLine("Getting the AutoCAD aplication object...");

            IAcadApplication acad;

            acad         = new AcadApplication();
            acad.Visible = false;
            // to do: figure out how to instantiate acad in such a way that no flashing windows appear.  Even when we set acad.Visibile = false,
            // the layer manager window and other accessory AutoCAD windows sometimes appear.
            //I want to run AutoCAD fully as a background process.
            // would it make sense to use the special command-line version of AutoCAD for this instead of the COM object?  (acconsole.exe, I think)
            String acadProgramDirectory = System.IO.Path.GetDirectoryName(acad.FullName);

            Console.WriteLine("acad.FullName: " + acad.FullName);
            Console.WriteLine("acadProgramDirectory: " + acadProgramDirectory);

            Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + acadProgramDirectory);
            //SetDllDirectory(dllDirectory);

            //Console.WriteLine("Directory.GetCurrentDirectory(): " + Directory.GetCurrentDirectory());
            //Directory.SetCurrentDirectory(dllDirectory);
            //Console.WriteLine("Directory.GetCurrentDirectory(): " + Directory.GetCurrentDirectory());
            //IAcadApplication acad;
            //acad = new AcadApplication();
            Console.WriteLine("checkpoint -2");

            // it seems that we have to arrange to have the following dlls in the same directory as the acad-sheetset-to-pdf executable in order to succesfully create
            // an instance of the AcSmSheetSetMgr object, below.
            // acpal.dll
            // acui24res.dll
            // adui24res.dll
            // anavRes.dll

            //Even if we run executable with the initial working directory being the autocad install directory (which is the primary residence of those dlls), we still get errors about not being able to find entry points.

            int libIdOfAcpal = 0;

            //int libIdOfAcui24res = 0;
            //int libIdOfAdui24res = 0;
            //int libIdOfAnavRes = 0;

            libIdOfAcpal = LoadLibrary(acadProgramDirectory + @"\" + "acpal.dll");
            //libIdOfAcpal = LoadLibrary("acpal.dll");
            // for reasons that I do not fully understand, manually loading acpal.dll with the above call to LoadLibrary will prevent the below "new AcSmSheetSetMgr()" statement from throwing an error abot not being able
            // to find dlls.

            //libIdOfAcui24res = LoadLibrary(dllDirectory + @"\" + "acui24res.dll");
            //libIdOfAdui24res = LoadLibrary(dllDirectory + @"\" + "adui24res.dll");
            //libIdOfAnavRes = LoadLibrary(dllDirectory + @"\" + "anavRes.dll");

            Console.WriteLine("libIdOfAcpal: " + libIdOfAcpal);
            //Console.WriteLine("libIdOfAcui24res: " + libIdOfAcui24res);
            //Console.WriteLine("libIdOfAdui24res: " + libIdOfAdui24res);
            //Console.WriteLine("libIdOfAnavRes: " + libIdOfAnavRes);


            sheetSetMgr = new AcSmSheetSetMgr();
            Console.WriteLine("attempting to open " + nameOfSheetsetFile);
            //Environment.CurrentDirectory = @"C:\Program Files\Autodesk\AutoCAD 2019";
            sheetdb = sheetSetMgr.OpenDatabase(nameOfSheetsetFile, bFailIfAlreadyOpen: false);
            Console.WriteLine("checkpoint -1");
            String nameOfDwgFileContainingThePageSetup;
            String nameOfThePageSetup;

            //IAcadApplication acad;
            //acad = new AcadApplication();

            if (sheetdb.GetLockStatus() == 0)
            {
                sheetdb.LockDb(sheetdb);
            }                                                              //it may not be necessary to lock the sheetset, because I am only reading from it, not writing to it.
            sheetSet = sheetdb.GetSheetSet();
            if (sheetdb.GetLockStatus() != 0)
            {
                sheetdb.UnlockDb(sheetdb);
            }
            //read the page setup override information from the sheet set.
            nameOfDwgFileContainingThePageSetup = sheetSet.GetAltPageSetups().ResolveFileName();

            Console.WriteLine("checkpoint 0");
            IAcSmNamedAcDbObjectReference myNamedAcDbObjectReference;

            myNamedAcDbObjectReference = sheetSet.GetDefAltPageSetup();
            //nameOfThePageSetup = myNamedAcDbObjectReference.GetName();
            // the above is not working because sheetSet.GetDefAltPageSetup() returns null.
            // I suspect that sheetSet.GetDefAltPageSetup() only returns something when
            // this code is being run within the Autocad process.
            //as a work-around, we might have to open the dwg file containing the page setup, and read out the page setup names from it.
            Console.WriteLine("checkpoint 1");

            acad.Visible = false;
            Console.WriteLine("checkpoint 2");
            IAcadDocument documentContainingThePageSetup = acad.Documents.Open(Name: nameOfDwgFileContainingThePageSetup, ReadOnly: true);

            while (!AcadIsAvailableAndQuiescent(acad))
            {
                Console.WriteLine("waiting for autoCAD to become available and quiescent.");
            }

            Console.WriteLine("documentContainingThePageSetup.Name: " + documentContainingThePageSetup.Name);                                         //             documentContainingThePageSetup.Name

            Console.WriteLine("documentContainingThePageSetup.PlotConfigurations.Count: " + documentContainingThePageSetup.PlotConfigurations.Count); //             documentContainingThePageSetup.PlotConfigurations.Count


            foreach (IAcadPlotConfiguration thisPlotConfiguration in documentContainingThePageSetup.PlotConfigurations)
            {
                Console.WriteLine("found a PlotConfiguration: " + thisPlotConfiguration.Name);
            }
            nameOfThePageSetup = documentContainingThePageSetup.PlotConfigurations.Item(0).Name;
            documentContainingThePageSetup.Close(SaveChanges: false);
            Console.WriteLine("nameOfDwgFileContainingThePageSetup: " + nameOfDwgFileContainingThePageSetup);
            Console.WriteLine("nameOfThePageSetup: " + nameOfThePageSetup);

            string dsdContent = "";

            dsdContent +=
                "[DWF6Version]" + "\r\n" +
                "Ver=1" + "\r\n" +
                "[DWF6MinorVersion]" + "\r\n" +
                "MinorVer=1" + "\r\n";

            IAcSmEnumComponent myAcSmEnumComponent = sheetSet.GetSheetEnumerator();
            IAcSmComponent     thisAcSmComponent;
            IAcSmSheet         thisSheet;

            while ((thisAcSmComponent = myAcSmEnumComponent.Next()) != null)
            {
                Console.WriteLine(thisAcSmComponent.GetObjectId().GetPersistObject().GetTypeName());
                thisSheet = (IAcSmSheet)thisAcSmComponent.GetObjectId().GetPersistObject();
                Console.WriteLine("thisSheet.GetName(): " + thisSheet.GetName());                                         //                 thisSheet.GetName()
                Console.WriteLine("thisSheet.GetLayout().GetName(): " + thisSheet.GetLayout().GetName());                 //                 thisSheet.GetLayout().GetName()
                Console.WriteLine("thisSheet.GetLayout().ResolveFileName(): " + thisSheet.GetLayout().ResolveFileName()); //                 thisSheet.GetLayout().ResolveFileName()
                Console.WriteLine("thisSheet.GetLayout().GetFileName(): " + thisSheet.GetLayout().GetFileName());         //                 thisSheet.GetLayout().GetFileName()

                dsdContent +=
                    "[DWF6Sheet:" + thisSheet.GetName() + "]" + "\r\n" +
                    "DWG=" + thisSheet.GetLayout().ResolveFileName() + "\r\n" +
                    "Layout=" + thisSheet.GetLayout().GetName() + "\r\n" +
                    "Setup=" + nameOfThePageSetup + "|" + nameOfDwgFileContainingThePageSetup + "\r\n" +
                    "OriginalSheetPath=" + thisSheet.GetLayout().ResolveFileName() + "\r\n" +
                    "Has Plot Port=" + "0" + "\r\n" +
                    "Has3DDWF=" + "0" + "\r\n";
            }

            dsdContent +=
                "[Target]" + "\r\n" +
                "Type=6" + "\r\n" +
                "DWF=" + nameOfPdfOutputFile + "\r\n" +
                "OUT=" + System.IO.Path.GetDirectoryName(nameOfPdfOutputFile) /*+ System.IO.Path.DirectorySeparatorChar*/ + "\r\n" +
                "PWD=" + "" + "\r\n" +
                "[PdfOptions]" + "\r\n" +
                "IncludeHyperlinks=FALSE" + "\r\n" +
                "CreateBookmarks=FALSE" + "\r\n" +
                "CaptureFontsInDrawing=TRUE" + "\r\n" +
                "ConvertTextToGeometry=FALSE" + "\r\n" +
                "VectorResolution=600" + "\r\n" +
                "RasterResolution=400" + "\r\n" +
                "[AutoCAD Block Data]" + "\r\n" +
                "IncludeBlockInfo=0" + "\r\n" +
                "BlockTmplFilePath=" + "\r\n" +
                "[SheetSet Properties]" + "\r\n" +
                "IsSheetSet=TRUE" + "\r\n" +
                "IsHomogeneous=FALSE" + "\r\n" +
                "SheetSet Name=" + sheetSet.GetName() + "\r\n" +
                "NoOfCopies=1" + "\r\n" +
                "PlotStampOn=FALSE" + "\r\n" +
                "ViewFile=FALSE" + "\r\n" +
                "JobID=0" + "\r\n" +
                "SelectionSetName=" + "\r\n" +
                "AcadProfile=" + "\r\n" +
                "CategoryName=" + "\r\n" +
                "LogFilePath=" + nameOfTheTemporaryPlotLogFile + "\r\n" +
                "IncludeLayer=FALSE" + "\r\n" +
                "LineMerge=FALSE" + "\r\n" +
                "CurrentPrecision=" + "\r\n" +
                "PromptForDwfName=FALSE" + "\r\n" +
                "PwdProtectPublishedDWF=FALSE" + "\r\n" +
                "PromptForPwd=FALSE" + "\r\n" +
                "RepublishingMarkups=FALSE" + "\r\n" +
                "DSTPath=" + nameOfSheetsetFile + "\r\n" +
                "PublishSheetSetMetadata=FALSE" + "\r\n" +
                "PublishSheetMetadata=FALSE" + "\r\n" +
                "3DDWFOptions=0 0" + "\r\n" + "\r\n" +
                "";

            System.IO.File.WriteAllText(path: nameOfTheTemporaryDsdFile, contents: dsdContent);

            Console.WriteLine(nameOfTheTemporaryDsdFile);

            if (sheetdb.GetLockStatus() != 0)
            {
                sheetdb.UnlockDb(sheetdb);
            }
            IAcadDocument workingDocument = acad.Documents.Add();

            while (acad.GetAcadState().IsQuiescent == false)
            {
                Console.WriteLine("waiting for autoCAD to become quiescent.");
            }
            workingDocument.SetVariable("FILEDIA", 0);
            workingDocument.SendCommand("-PUBLISH" + "\n" + nameOfTheTemporaryDsdFile + "\n");


            try
            {
                //make a copy of the log file so that we can inspect the log file even after the clean-up behavior built into AutoCAD's publish routine has deleted the original log file.
                System.IO.File.Copy(nameOfTheTemporaryPlotLogFile, baseName + "2" + "-plot" + ".log", overwrite: true);
                //Actually, the above attempt to copy does not seem to result in the expected output log file.  However, it does seem to result in having a csv version of the log file left behind in the temp folder.
            }
            catch (Exception)
            {
                Console.WriteLine("Attempted and failed to make a copy of the temporary plot log file. " + nameOfTheTemporaryPlotLogFile);
                //throw;
            }


            workingDocument.Close(SaveChanges: false);
            while (acad.GetAcadState().IsQuiescent == false)
            {
                Console.WriteLine("waiting for autoCAD to become quiescent.");
            }
            // Keep the console window open
            //Console.WriteLine("Press any key to exit."); Console.ReadKey();
            acad.Quit();

            if (libIdOfAcpal > 0)
            {
                FreeLibrary(libIdOfAcpal);
            }
            //if (libIdOfAcui24res > 0) { FreeLibrary(libIdOfAcui24res); }
            //if (libIdOfAdui24res > 0) { FreeLibrary(libIdOfAdui24res); }
            //if (libIdOfAnavRes > 0) { FreeLibrary(libIdOfAnavRes); }



            return(0);
        }
Exemplo n.º 7
0
        private void iconButton3_Click(object sender, EventArgs e)
        {
            string nombre;

            foreach (string g in Modulo.listaFinal)
            {
                nombre = Modulo.RutaGuardado + "\\" + g + ".dwg";

                File.Copy(Modulo.RutaAutocad, nombre, true);
            }
            List <Ejecucion> listaEjecucion = new List <Ejecucion>();
            Ejecucion        ejecucion;

            foreach (Localidades k in Modulo.matrizRaiz)
            {
                foreach (string z in Modulo.listaFinal)
                {
                    if (z == k.nombre_plano)

                    {
                        ejecucion      = new Ejecucion();
                        ejecucion.loc  = k.id;
                        ejecucion.ruta = k.nombre_plano;
                        listaEjecucion.Add(ejecucion);
                    }
                }
            }
            ejecucion = null;
            //inicializacion del autocad
            Autodesk.AutoCAD.Interop.AcadApplication AcadApp = new AcadApplication();

            Autodesk.AutoCAD.Interop.AcadDocument doc;
            AcadApp.Visible = true;
            string rutaAutocad;
            //creacion de los objetos en listas

            obExcel f = new obExcel();

            IEnumerable <Vanos>         vanos;
            IEnumerable <Postes>        postes;
            IEnumerable <Luminarias>    luminarias;
            IEnumerable <Subestaciones> subestaciones;
            IEnumerable <VistasC>       vistasCajetines;
            IEnumerable <VistasD>       vistasDibujo;
            IEnumerable <Layers>        capas;
            IEnumerable <Cajetines>     cajetienes;

            double[] pto  = new double[3];
            double[] pto2 = new double[3];
            double[] pto3 = new double[3];
            double[] pto4 = new double[3];
            pto[2]  = 0.0;
            pto2[2] = 0.0;
            pto3[2] = 0.0;
            pto4[2] = 0.0;
            AcadLine           lin;
            AcadBlockReference block;
            AcadLayer          layer;
            AcadPViewport      vistaCajetin;
            AcadPViewport      vistaPlano;
            AcadAcCmColor      color = null;
            AcadDimAligned     dim;
            AcadDimAligned     con;


            try
            {
                color = AcadApp.GetInterfaceObject("AutoCAD.AcCmColor.17") as AcadAcCmColor;
            }
            catch { };
            try
            {
                color = AcadApp.GetInterfaceObject("AutoCAD.AcCmColor.18") as AcadAcCmColor;
            }
            catch { };
            try
            {
                color = AcadApp.GetInterfaceObject("AutoCAD.AcCmColor.19") as AcadAcCmColor;
            }
            catch { };
            try
            {
                color = AcadApp.GetInterfaceObject("AutoCAD.AcCmColor.20") as AcadAcCmColor;
            }
            catch { };
            try
            {
                color = AcadApp.GetInterfaceObject("AutoCAD.AcCmColor.21") as AcadAcCmColor;
            }
            catch { };
            try
            {
                color = AcadApp.GetInterfaceObject("AutoCAD.AcCmColor.22") as AcadAcCmColor;
            }
            catch { };
            try
            {
                color = AcadApp.GetInterfaceObject("AutoCAD.AcCmColor.23") as AcadAcCmColor;
            }
            catch { };

            var book = new ExcelQueryFactory(Modulo.RutaExcel);

            listaEjecucion.Distinct <Ejecucion>();


            foreach (Ejecucion loc in listaEjecucion)
            {
                rutaAutocad = Modulo.RutaGuardado + "\\" + loc.ruta + ".dwg";
                doc         = AcadApp.Documents.Open(rutaAutocad);



                vanos           = f.VanosData(loc.loc, book);
                postes          = f.PostesData(loc.loc, book);
                luminarias      = f.LuminariasData(loc.loc, book);
                subestaciones   = f.SubestacionesData(loc.loc, book);
                vistasCajetines = f.VistasCData(book);
                vistasDibujo    = f.VistasDData(loc.loc, book);
                cajetienes      = f.CajetinesData(loc.loc, book);
                capas           = f.LayersData(book);

                foreach (Layers g in capas)
                {
                    color.SetRGB(g.red, g.green, g.blue);
                    layer           = doc.Layers.Add(g.nombre_capa);
                    layer.TrueColor = color;
                }

                //dibujamos los vanos
                if (VanosBox.Checked)
                {
                    foreach (Vanos g in vanos)
                    {
                        pto[0] = g.x_inicial;
                        pto[1] = g.y_inicial;

                        pto2[0] = g.x_final;
                        pto2[1] = g.y_final;

                        pto3[0] = pto[0] / 2 + pto2[0] / 2;
                        pto3[1] = pto[1] / 2 + pto2[1] / 2;

                        lin                      = doc.ModelSpace.AddLine(pto, pto2);
                        lin.Layer                = "_AereoCond";
                        dim                      = doc.ModelSpace.AddDimAligned(pto, pto2, pto3);
                        dim.StyleName            = "ACOT-LP-FRANK";
                        dim.VerticalTextPosition = AcDimVerticalJustification.acAbove;
                        dim.Layer                = "_CotaCond";
                        con                      = doc.ModelSpace.AddDimAligned(pto, pto2, pto3);
                        con.TextOverride         = g.conductor;
                        con.StyleName            = "ACOT-LP-FRANK";
                        con.VerticalTextPosition = AcDimVerticalJustification.acUnder;
                        con.Layer                = "_TipoCond";
                    }
                }
                //metodo de postes
                if (Postesbox.Checked)
                {
                    foreach (Postes g in postes)
                    {
                        pto[0]      = g.x_poste;
                        pto[1]      = g.y_poste;
                        block       = doc.ModelSpace.InsertBlock(pto, g.bloque, 1, 1, 1, 0);
                        block.Layer = "_Postes";
                        var blocAtri = block.GetAttributes();
                        blocAtri[0].TextString = g.altura;
                        blocAtri[1].TextString = g.estado;
                        blocAtri[2].TextString = g.material;
                        blocAtri[3].TextString = g.cod_poste;
                    }
                }
                //metodo de luminarias
                if (LumBox.Checked)
                {
                    foreach (Luminarias g in luminarias)
                    {
                        pto[0]      = g.x_luminaria;
                        pto[1]      = g.y_luminaria;
                        block       = doc.ModelSpace.InsertBlock(pto, "luminaria", 1, 1, 1, 0);
                        block.Layer = "_Luminaria";
                        var blocAtri = block.GetAttributes();
                        blocAtri[0].TextString = g.potencia;
                        blocAtri[1].TextString = g.altura;
                        blocAtri[2].TextString = g.codigo_luminaria;
                    }
                }
                //metodo de subestaciones
                if (SedBox.Checked)
                {
                    foreach (Subestaciones g in subestaciones)
                    {
                        pto[0]      = g.x_subestacion;
                        pto[1]      = g.y_subestacion;
                        block       = doc.ModelSpace.InsertBlock(pto, g.bloque, 25, 25, 25, 0);
                        block.Layer = "_Seds";
                        var blocAtri = block.GetAttributes();
                        blocAtri[0].TextString = g.potencia;
                        blocAtri[1].TextString = g.codigo_subestacion;
                    }
                }

                //metodo de creacion de vistas en cajetines

                if (CajBox.Checked)
                {
                    foreach (VistasC g in vistasCajetines)
                    {
                        pto[0]          = g.x_centro;
                        pto[1]          = g.y_centro;
                        pto2[0]         = g.x_inicial;
                        pto2[1]         = g.y_inicial;
                        pto3[0]         = g.x_final;
                        pto3[1]         = g.y_final;
                        doc.ActiveSpace = AcActiveSpace.acPaperSpace;
                        vistaCajetin    = doc.PaperSpace.AddPViewport(pto, g.ancho, g.largo);
                        vistaCajetin.Display(true);
                        vistaCajetin.ViewportOn = true;
                        doc.MSpace = true;
                        AcadApp.ActiveDocument.ActivePViewport = vistaCajetin;
                        AcadApp.ZoomWindow(pto2, pto3);
                        doc.MSpace = false;
                    }

                    //metodo de creacion de vistas en planos


                    foreach (VistasD g in vistasDibujo)
                    {
                        pto[0]          = g.x_centro;
                        pto[1]          = g.y_centro;
                        pto2[0]         = g.x_inicial;
                        pto2[1]         = g.y_inicial;
                        pto3[0]         = g.x_final;
                        pto3[1]         = g.y_final;
                        doc.ActiveSpace = AcActiveSpace.acPaperSpace;
                        vistaPlano      = doc.PaperSpace.AddPViewport(pto, g.ancho, g.largo);
                        vistaPlano.Display(true);
                        vistaPlano.ViewportOn = true;
                        doc.MSpace            = true;
                        AcadApp.ActiveDocument.ActivePViewport = vistaPlano;
                        AcadApp.ZoomWindow(pto2, pto3);
                        doc.MSpace = false;
                    }

                    //metodo de cajetines

                    foreach (Cajetines g in cajetienes)
                    {
                        pto[0]      = 0;
                        pto[1]      = 0;
                        block       = doc.PaperSpace.InsertBlock(pto, "cajetin", 1, 1, 1, 0);
                        block.Layer = "_MarcoPlano";
                        var blocAtri = block.GetAttributes();
                        blocAtri[0].TextString  = g.escala;
                        blocAtri[1].TextString  = g.fecha;
                        blocAtri[2].TextString  = g.plano;
                        blocAtri[3].TextString  = g.n_expediente;
                        blocAtri[4].TextString  = g.departamento;
                        blocAtri[5].TextString  = g.provincia;
                        blocAtri[6].TextString  = g.distrito;
                        blocAtri[7].TextString  = g.revisado;
                        blocAtri[8].TextString  = g.aprobado;
                        blocAtri[9].TextString  = g.dibujado;
                        blocAtri[10].TextString = g.anexo;
                    }
                }
                doc.Save();
                doc.Close();
            }
            book.Dispose();
            AcadApp.Quit();
        }
Exemplo n.º 8
0
        public void New()
        {
            try
            {
                string serverIP   = CIni.ReadINI("updateconfig", "ServerIP");
                int    serverPort = int.Parse(CIni.ReadINI("updateconfig", "ServerPort"));
                if (VersionHelper.HasNewVersion(serverIP, serverPort))
                {
                    if (MessageBox.Show("服务器端发布了更新,请退出AutoCAD然后运行获取更新程序", "提示",
                                        MessageBoxButtons.OKCancel
                                        , MessageBoxIcon.Warning) == DialogResult.OK)
                    {
                        AcadApplication AcadApp = (AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
                        AcadApp.Quit();

                        return;
                        //MessageBox.Show("完成关闭");
                    }
                }
            }
            finally
            {
                ImportDataFrm pImportDataFrm = new ImportDataFrm();
                if (pImportDataFrm.ShowDialog() == DialogResult.OK)
                {
                    pWork = new BackgroundWorker();
                    pWork.WorkerReportsProgress      = true;
                    pWork.WorkerSupportsCancellation = true;
                    pWork.DoWork          += PWork_DoWork;
                    pWork.ProgressChanged += PWork_ProgressChanged;


                    pWork.RunWorkerCompleted += new RunWorkerCompletedEventHandler(pWork_RunWorkerCompleted);

                    pProgressFrm             = HR.Controls.ProgressFrm.GetInstance();
                    pProgressFrm.CanCancle   = false;
                    pProgressFrm.FormClosed += new FormClosedEventHandler(pProgressFrm_FormClosed);
                    pProgressFrm.SetProgressStyle(ProgressBarStyle.Blocks);
                    pProgressFrm.Text = "数据成图";
                    pWork.RunWorkerAsync(pImportDataFrm.pWorkArgument);
                    //pProgressFrm.FormClosing += new FormClosingEventHandler(pProgressFrm_FormClosing);

                    /*    pCADObjectEditCtrl = new CADObjectEditCtrl();
                     *
                     *  Autodesk.AutoCAD.Windows.PaletteSet ps = new Autodesk.AutoCAD.Windows.PaletteSet("管网管理");
                     *
                     *  ps.Style = PaletteSetStyles.ShowTabForSingle;
                     *  ps.Style = PaletteSetStyles.NameEditable;
                     *  ps.Style = PaletteSetStyles.ShowPropertiesMenu;
                     *  ps.Style = PaletteSetStyles.ShowAutoHideButton;
                     *  ps.Style = PaletteSetStyles.ShowCloseButton;
                     *
                     *  ps.Dock = DockSides.Left;
                     *  ps.Visible = true;
                     *  ps.MinimumSize = new System.Drawing.Size(230, 490);
                     *  ps.Size = new System.Drawing.Size(230, 490);
                     *
                     *  ps.Add("管网管理", pCADObjectEditCtrl);
                     *  ps.Activate(0);*/
                }
            }
        }
Exemplo n.º 9
0
        private void Thread_print1()
        {
            AcadDocument drawing = null;

            

            bool islock = false;
            //mulInfo TaskInfo;
            DB.BLL.TASK bll_Task = new DB.BLL.TASK();
            while (true)
            {
                if (0 < bll_Task.GetModelList("1=1").Count)//判断任务列表是否为空
                {
                    if (TaskFlag == 2)
                    {
                        TaskFlag = 0;
                    }
                    DB.Model.TASK model_Task;
                    if (0 < bll_Task.GetModelList("ISPRINTING=0").Count )//判断是否有未进行的打印任务
                    {
                        try
                        {
                            model_Task = bll_Task.GetModelList("ISPRINTING=0")[0];
                        }
                        catch { continue; }
                        if (0 == model_Task.ORDERED)//如果此任务没有被预约,先预约此任务,此次循环并不开始打印,这是为了防止多个cad进程同时打印一个任务
                        {
                            model_Task.ORDERED = 1;
                            bll_Task.Update(model_Task);
                        }
                        else if (1 == model_Task.ORDERED)//如果此任务已经被预约,且预约者是进程1,那么开始打印任务
                        {
                            model_Task.ISPRINTING = 1;
                            model_Task.PRINTING_TIME = System.DateTime.Now;
                            bll_Task.Update(model_Task);
                            string fname = model_Task.FILE_FULLNAME;
                            bool isFinish = false;
                            while (!isFinish)
                            {
                                try
                                {
                                    app1.Documents.Open(fname, true);
                                    
                                    isFinish = true;
                                }
                                catch
                                {
                                    isFinish = false;
                                }
                            }
                            //防止CAD反应慢,上一步任务未完成就开始了下一步命令
                            //List<DB.Model.TASK> model_Task = bll_Task.GetModelList("1=1");

                            isFinish = false;
                            while (!isFinish)
                            {
                                try
                                {
                                    drawing = app1.ActiveDocument; isFinish = true;
                                }
                                catch
                                {
                                    isFinish = false;
                                }
                            }
                            isFinish = false;
                            while (!isFinish)
                            {
                                try
                                {
                                    drawing.SetVariable("BACKGROUNDPLOT", 0);
                                    drawing.ActiveLayout.CenterPlot = true;//居中
                                    drawing.ActiveLayout.ConfigName = model_Task.PRINTER;
                                    drawing.ActiveLayout.PlotRotation = AcPlotRotation.ac0degrees;
                                    drawing.ActiveLayout.UseStandardScale = true;
                                    drawing.ActiveLayout.StandardScale = AcPlotScale.acScaleToFit;
                                    drawing.ActiveLayout.PlotType = AcPlotType.acExtents;
                                    drawing.ActiveLayout.CanonicalMediaName = model_Task.PAPER;
                                    
                                    isFinish = true;
                                }
                                catch
                                {
                                    isFinish = false;
                                }
                            }
                            #region 截取文件名
                            string[] dwgFullName = fname.Split('\\');
                            string[] dwgName = dwgFullName[dwgFullName.Length - 1].Split('.');
                            string pureName = null;
                            for (int i = 0; i < dwgName.Length - 2; i++)
                            {
                                pureName += dwgName[i];
                                pureName += ".";
                            }

                            pureName += dwgName[dwgName.Length - 2];
                            string SaveFileName = model_Task.SAVE_PATH + "/" + pureName;
                            //drawing.SaveAs("C:/Users/JabinGuo/Desktop/convert", AcSaveAsType.ac2007_dxf);
                            #endregion
                            islock = false;
                            while (!islock)
                            {
                                try
                                {
                                    islock = Monitor.TryEnter(drawing);
                                }
                                catch
                                {
                                   
                                }
                            }
                            bool isfinish = false;
                            while (!isfinish)
                            {
                                try
                                {
                                    isfinish = drawing.Plot.PlotToFile(SaveFileName);
                                }
                                catch { }
                            }
                            Monitor.Exit(drawing);
                            drawing.Close(false);
                            bll_Task.Delete(model_Task.TASK_GUID);
                        }
                    } 
                    if (0 < bll_Task.GetModelList("ISPRINTING!=0").Count)//如果长时间没有完成打印任务,说明cad卡死,关闭此进程并重新打开
                    {
                        try
                        {
                            model_Task = bll_Task.GetModelList("ISPRINTING!=0")[0];
                        }
                        catch { continue; }
                        if (2 < System.DateTime.Now.Subtract((DateTime)model_Task.PRINTING_TIME).Minutes)
                        {
                            switch (model_Task.ISPRINTING)
                            {
                                case 1:
                                    try
                                    {
                                        app1.Quit();
                                        
                                    }catch/*(Exception e) */{ /*MessageBox.Show(e.ToString());*/ }
                                    Thread.Sleep(2000);
                                    app1 = NewCAD();
                                    break;
                                case 2:
                                    try
                                    {
                                        //app2.ActiveDocument.Close(false);
                                        app2.Quit();
                                    }catch/*(Exception e)*/ { /*MessageBox.Show(e.ToString());*/ }
                                    Thread.Sleep(2000);
                                    app2 = NewCAD();
                                    break;
                                default:
                                    MessageBox.Show("找不到打印{0}的进程", model_Task.FILE_FULLNAME);
                                    break;
                            }
                            model_Task.ORDERED = 0;
                            model_Task.ISPRINTING = 0;
                            model_Task.PRINTING_TIME = System.DateTime.Now;
                            bll_Task.Update(model_Task);
                        }
                    }                   
                }
                else
                {
                    if (0 == TaskFlag)
                    {
                        MessageBox.Show("打印完成");
                        TaskFlag = 1;
                    }
                    if (1 == TaskFlag)
                    {
                        TaskFlag = 2;
                    }
                    continue;
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 打印线程,可传入参数
        /// </summary>
        /// <param name="obj"></param>
        private void Thread_print(object obj)
        {
            bool islock = false;
            while (!islock)
            {
                try
                {
                    islock = Monitor.TryEnter(progressNum);
                    if (islock)
                    {
                        progressNum.num++;
                        Monitor.Exit(progressNum);
                    }
                }
                catch { }
            }
            AcadDocument drawing=null;
                        
            mulInfo str=(mulInfo)obj;
            AcadApplication app = NewCAD();

            string[] PrintNames_inThread = str.Files; 
            foreach (string fname in PrintNames_inThread)
            {
                bool isFinish = false;
                while (!isFinish)
                {
                    try
                    {                        
                        app.Documents.Open(fname,true);
                        isFinish = true;
                    }
                    catch
                    {
                        isFinish = false;
                    }
                }
                //防止AutoCAD响应慢,上一步还未响应程序就开始下一步命令,不断try直到成功执行

                isFinish = false;
                while (!isFinish)
                {
                    try
                    { drawing = app.ActiveDocument; isFinish = true; }
                    catch
                    { isFinish = false; }
                }
                isFinish = false;
                while (!isFinish)
                {
                    try
                    {
                        drawing.SetVariable("BACKGROUNDPLOT", 0);
                        drawing.ActiveLayout.CenterPlot = true;//居中
                        drawing.ActiveLayout.ConfigName = str.Selected_Printer;
                        
                        drawing.ActiveLayout.UseStandardScale = true;
                        drawing.ActiveLayout.StandardScale = AcPlotScale.acScaleToFit;
                        drawing.ActiveLayout.PlotType = AcPlotType.acExtents;
                        drawing.ActiveLayout.CanonicalMediaName = str.Selected_Paper;
                        isFinish = true;
                    }
                    catch
                    { isFinish = false; }
                }
        #region 截取文件名
                string[] dwgFullName = fname.Split('\\');
                string[] dwgName = dwgFullName[dwgFullName.Length - 1].Split('.');
                string pureName = null;
                for (int i = 0; i < dwgName.Length - 2; i++)
                {
                    pureName += dwgName[i];
                    pureName += ".";
                }

                pureName += dwgName[dwgName.Length - 2];
                string SaveFileName = str.SaveAddr + "/" + pureName;
                //drawing.SaveAs("C:/Users/JabinGuo/Desktop/convert", AcSaveAsType.ac2007_dxf);
        #endregion
                islock = false;
                while (!islock)
                {
                    try
                    {
                        islock = Monitor.TryEnter(drawing);
                    }
                    catch {
                        //此处测试过exception
                    }
                }
                bool isfinish = false;
                while (!isfinish)
                {
                    try
                    {
                        isfinish = drawing.Plot.PlotToFile(SaveFileName);
                        
                    }
                    catch  {  }
                }
                Monitor.Exit(drawing);
                drawing.Close(false);
                
            }
            app.Quit();
            islock = false;
                while (!islock)
                {
                    try
                    {
                        islock = Monitor.TryEnter(progressNum);
                        if (islock)
                        {
                            progressNum.num--;                            
                        }
                    }
                    catch (Exception e) { MessageBox.Show(e.Message); }
                }Monitor.Exit(progressNum);
            
            return;
            //button_FindFile.Enabled = true;
        }
Exemplo n.º 11
0
        static int Main(string[] args)
        {
            Options commandLineOptions = new Options();
            bool    parseErrorsOccured = false;

            CommandLine.Parser.Default.ParseArguments <Options>(args)
            .WithParsed <Options>(opts => commandLineOptions      = opts)
            .WithNotParsed <Options>((errs) => parseErrorsOccured = true);

            if (parseErrorsOccured)
            {
                //Console.WriteLine("some parse errors occured. ahoy.");
                return(1);
            }



            //*****parse the command-line arguments*****
            //for now, I will simply hard code these values.
            String nameOfSheetsetFile            = commandLineOptions.SheetSetFile;
            String nameOfPdfOutputFile           = commandLineOptions.OutputPdfFile;
            String baseName                      = System.IO.Path.GetTempFileName();
            String nameOfTheTemporaryDsdFile     = baseName + ".dsd";
            String nameOfTheTemporaryPlotLogFile = baseName + "-plot" + ".log";

            //TO DO: parse and verify the real command-line arguments, compose a help message.

            //*****read the sheetset file and construct a dsd file accordingly*****
            IAcSmSheetSetMgr sheetSetMgr;
            IAcSmDatabase    sheetdb;
            IAcSmSheetSet    sheetSet;

            sheetSetMgr = new AcSmSheetSetMgr();
            Console.WriteLine("attempting to open " + nameOfSheetsetFile);
            Environment.CurrentDirectory = "C:\\Program Files\\Autodesk\\AutoCAD 2019";
            sheetdb = sheetSetMgr.OpenDatabase(nameOfSheetsetFile, bFailIfAlreadyOpen: false);
            Console.WriteLine("checkpoint -1");
            String           nameOfDwgFileContainingThePageSetup;
            String           nameOfThePageSetup;
            IAcadApplication acad;

            acad = new AcadApplication();

            if (sheetdb.GetLockStatus() == 0)
            {
                sheetdb.LockDb(sheetdb);
            }                                                              //it may not be necessary to lock the sheetset, because I am only reading from it, not writing to it.
            sheetSet = sheetdb.GetSheetSet();
            if (sheetdb.GetLockStatus() != 0)
            {
                sheetdb.UnlockDb(sheetdb);
            }
            //read the page setup override information from the sheet set.
            nameOfDwgFileContainingThePageSetup = sheetSet.GetAltPageSetups().ResolveFileName();

            Console.WriteLine("checkpoint 0");
            IAcSmNamedAcDbObjectReference myNamedAcDbObjectReference;

            myNamedAcDbObjectReference = sheetSet.GetDefAltPageSetup();
            //nameOfThePageSetup = myNamedAcDbObjectReference.GetName();
            // the above is not working because sheetSet.GetDefAltPageSetup() returns null.
            // I suspect that sheetSet.GetDefAltPageSetup() only returns something when
            // this code is being run within the Autocad process.
            //as a work-around, we might have to open the dwg file containing the page setup, and read out the page setup names from it.
            Console.WriteLine("checkpoint 1");
            acad.Visible = false;
            Console.WriteLine("checkpoint 2");
            IAcadDocument documentContainingThePageSetup = acad.Documents.Open(Name: nameOfDwgFileContainingThePageSetup, ReadOnly: true);

            while (acad.GetAcadState().IsQuiescent == false)
            {
                Console.WriteLine("waiting for autoCAD to become quiescent.");
            }

            Console.WriteLine("documentContainingThePageSetup.Name: " + documentContainingThePageSetup.Name);                                         //             documentContainingThePageSetup.Name

            Console.WriteLine("documentContainingThePageSetup.PlotConfigurations.Count: " + documentContainingThePageSetup.PlotConfigurations.Count); //             documentContainingThePageSetup.PlotConfigurations.Count


            foreach (IAcadPlotConfiguration thisPlotConfiguration in documentContainingThePageSetup.PlotConfigurations)
            {
                Console.WriteLine("found a PlotConfiguration: " + thisPlotConfiguration.Name);
            }
            nameOfThePageSetup = documentContainingThePageSetup.PlotConfigurations.Item(0).Name;
            documentContainingThePageSetup.Close(SaveChanges: false);
            Console.WriteLine("nameOfDwgFileContainingThePageSetup: " + nameOfDwgFileContainingThePageSetup);
            Console.WriteLine("nameOfThePageSetup: " + nameOfThePageSetup);

            string dsdContent = "";

            dsdContent +=
                "[DWF6Version]" + "\r\n" +
                "Ver=1" + "\r\n" +
                "[DWF6MinorVersion]" + "\r\n" +
                "MinorVer=1" + "\r\n";

            IAcSmEnumComponent myAcSmEnumComponent = sheetSet.GetSheetEnumerator();
            IAcSmComponent     thisAcSmComponent;
            IAcSmSheet         thisSheet;

            while ((thisAcSmComponent = myAcSmEnumComponent.Next()) != null)
            {
                Console.WriteLine(thisAcSmComponent.GetObjectId().GetPersistObject().GetTypeName());
                thisSheet = (IAcSmSheet)thisAcSmComponent.GetObjectId().GetPersistObject();
                Console.WriteLine("thisSheet.GetName(): " + thisSheet.GetName());                                         //                 thisSheet.GetName()
                Console.WriteLine("thisSheet.GetLayout().GetName(): " + thisSheet.GetLayout().GetName());                 //                 thisSheet.GetLayout().GetName()
                Console.WriteLine("thisSheet.GetLayout().ResolveFileName(): " + thisSheet.GetLayout().ResolveFileName()); //                 thisSheet.GetLayout().ResolveFileName()
                Console.WriteLine("thisSheet.GetLayout().GetFileName(): " + thisSheet.GetLayout().GetFileName());         //                 thisSheet.GetLayout().GetFileName()

                dsdContent +=
                    "[DWF6Sheet:" + thisSheet.GetName() + "]" + "\r\n" +
                    "DWG=" + thisSheet.GetLayout().ResolveFileName() + "\r\n" +
                    "Layout=" + thisSheet.GetLayout().GetName() + "\r\n" +
                    "Setup=" + nameOfThePageSetup + "|" + nameOfDwgFileContainingThePageSetup + "\r\n" +
                    "OriginalSheetPath=" + thisSheet.GetLayout().ResolveFileName() + "\r\n" +
                    "Has Plot Port=" + "0" + "\r\n" +
                    "Has3DDWF=" + "0" + "\r\n";
            }

            dsdContent +=
                "[Target]" + "\r\n" +
                "Type=6" + "\r\n" +
                "DWF=" + nameOfPdfOutputFile + "\r\n" +
                "OUT=" + System.IO.Path.GetDirectoryName(nameOfPdfOutputFile) /*+ System.IO.Path.DirectorySeparatorChar*/ + "\r\n" +
                "PWD=" + "" + "\r\n" +
                "[PdfOptions]" + "\r\n" +
                "IncludeHyperlinks=FALSE" + "\r\n" +
                "CreateBookmarks=FALSE" + "\r\n" +
                "CaptureFontsInDrawing=TRUE" + "\r\n" +
                "ConvertTextToGeometry=FALSE" + "\r\n" +
                "VectorResolution=600" + "\r\n" +
                "RasterResolution=400" + "\r\n" +
                "[AutoCAD Block Data]" + "\r\n" +
                "IncludeBlockInfo=0" + "\r\n" +
                "BlockTmplFilePath=" + "\r\n" +
                "[SheetSet Properties]" + "\r\n" +
                "IsSheetSet=TRUE" + "\r\n" +
                "IsHomogeneous=FALSE" + "\r\n" +
                "SheetSet Name=" + sheetSet.GetName() + "\r\n" +
                "NoOfCopies=1" + "\r\n" +
                "PlotStampOn=FALSE" + "\r\n" +
                "ViewFile=FALSE" + "\r\n" +
                "JobID=0" + "\r\n" +
                "SelectionSetName=" + "\r\n" +
                "AcadProfile=" + "\r\n" +
                "CategoryName=" + "\r\n" +
                "LogFilePath=" + nameOfTheTemporaryPlotLogFile + "\r\n" +
                "IncludeLayer=FALSE" + "\r\n" +
                "LineMerge=FALSE" + "\r\n" +
                "CurrentPrecision=" + "\r\n" +
                "PromptForDwfName=FALSE" + "\r\n" +
                "PwdProtectPublishedDWF=FALSE" + "\r\n" +
                "PromptForPwd=FALSE" + "\r\n" +
                "RepublishingMarkups=FALSE" + "\r\n" +
                "DSTPath=" + nameOfSheetsetFile + "\r\n" +
                "PublishSheetSetMetadata=FALSE" + "\r\n" +
                "PublishSheetMetadata=FALSE" + "\r\n" +
                "3DDWFOptions=0 0" + "\r\n" + "\r\n" +
                "";

            System.IO.File.WriteAllText(path: nameOfTheTemporaryDsdFile, contents: dsdContent);

            Console.WriteLine(nameOfTheTemporaryDsdFile);

            if (sheetdb.GetLockStatus() != 0)
            {
                sheetdb.UnlockDb(sheetdb);
            }
            IAcadDocument workingDocument = acad.Documents.Add();

            while (acad.GetAcadState().IsQuiescent == false)
            {
                Console.WriteLine("waiting for autoCAD to become quiescent.");
            }
            workingDocument.SetVariable("FILEDIA", 0);
            workingDocument.SendCommand("-PUBLISH" + "\n" + nameOfTheTemporaryDsdFile + "\n");
            //make a copy of the log file so that we can inspect the log file even after the clean-up behavior built into AutoCAD's publish routine has deleted the original log file.
            System.IO.File.Copy(nameOfTheTemporaryPlotLogFile, baseName + "2" + "-plot" + ".log", overwrite: true);
            //Actually, the above attempt to copy does not seem to result in the expected output log file.  However, it does seem to result in having a csv version of the log file left behind in the temp folder.

            workingDocument.Close(SaveChanges: false);
            while (acad.GetAcadState().IsQuiescent == false)
            {
                Console.WriteLine("waiting for autoCAD to become quiescent.");
            }
            // Keep the console window open
            //Console.WriteLine("Press any key to exit."); Console.ReadKey();
            acad.Quit();

            return(0);
        }