public void OpenSheetSet()
        {
            // User Input: editor equals command line
            // To talk to the user you use the command line, aka the editor
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            PromptStringOptions pso = new PromptStringOptions("\nHello Nadia! \nWhat Sheet Set would you like to open?");

            pso.DefaultValue    = @"C:\Users\rhale\Documents\AutoCAD Sheet Sets\Squid666.dst";
            pso.UseDefaultValue = true;
            pso.AllowSpaces     = true;
            PromptResult pr = ed.GetString(pso);

            // Get a reference to the Sheet Set Manager object
            IAcSmSheetSetMgr sheetSetManager = default(IAcSmSheetSetMgr);

            sheetSetManager = new AcSmSheetSetMgr();

            // Open a Sheet Set file
            AcSmDatabase sheetSetDatabase = default(AcSmDatabase);

            //sheetSetDatabase = sheetSetManager.OpenDatabase(@"C:\Users\Robert\Documents\AutoCAD Sheet Sets\Expedia.dst", false);
            sheetSetDatabase = sheetSetManager.OpenDatabase(pr.StringResult, false);

            // Return the namd and description of the sheet set
            MessageBox.Show("Sheet Set Name: " + sheetSetDatabase.GetSheetSet().GetName() + "\nSheet Set Description: " + sheetSetDatabase.GetSheetSet().GetDesc());

            // Close the sheet set
            sheetSetManager.Close(sheetSetDatabase);
        }
        public static AMRSheetSet OpenSheetSet(string dstPath, bool failIfOpen)
        {
            IAcSmSheetSetMgr ssMgr = new AcSmSheetSetMgr();

            if (System.IO.File.Exists(dstPath))
            {
                AMRSheetSet curDatabase = new AMRSheetSet(ssMgr.OpenDatabase(dstPath, failIfOpen));
                return(curDatabase);
            }
            else
            {
                return(new AMRSheetSet());
            }
        }
        public void SyncProperties()
        {
            // User Input: editor equals command line
            // To talk to the user you use the command line, aka the editor
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            PromptResult pr1 = ed.GetFileNameForOpen("Hello Nadia, Please select the Sheet Set you would like to edit.");

            PromptStringOptions pso = new PromptStringOptions("\nHello Nadia! \nWhat version # is the drawing at?");

            //pso.DefaultValue = @"C:\Users\Robert\Documents\AutoCAD Sheet Sets\Expedia.dst";
            //pso.UseDefaultValue = true;
            pso.AllowSpaces = true;
            PromptResult pr            = ed.GetString(pso);
            string       versionNumber = pr.StringResult;

            pso = new PromptStringOptions("\nHello Nadia! \nWhat is the version issue date?");
            pr  = ed.GetString(pso);
            string versionIssueDate = pr.StringResult;

            // Get a reference to the Sheet Set Manager object
            IAcSmSheetSetMgr sheetSetManager = new AcSmSheetSetMgr();

            // Create a new sheet set file
            //AcSmDatabase sheetSetDatabase = sheetSetManager.CreateDatabase("C:\\Datasets\\CP318-4\\CP318-4.dst", "", true);
            //AcSmDatabase sheetSetDatabase = sheetSetManager.CreateDatabase(@"C:\Users\rhale\Documents\AutoCAD Sheet Sets\Expedia.dst", "", true);

            // Open a Sheet Set file
            AcSmDatabase sheetSetDatabase = default(AcSmDatabase);

            //sheetSetDatabase = sheetSetManager.OpenDatabase("C:\\Program Files\\AutoCAD 2010\\Sample\\Sheet Sets\\Architectural\\IRD Addition.dst", false);
            //sheetSetDatabase = sheetSetManager.OpenDatabase(@"C:\Users\rhale\Documents\AutoCAD Sheet Sets\Expedia.dst", false);
            sheetSetDatabase = sheetSetManager.OpenDatabase(pr1.StringResult, false);

            // Get the sheet set from the database
            AcSmSheetSet sheetSet = sheetSetDatabase.GetSheetSet();

            // Attempt to lock the database
            if (LockDatabase(ref sheetSetDatabase, true) == true)
            {
                // Get the folder the sheet set is stored in
                string sheetSetFolder = null;
                sheetSetFolder = sheetSetDatabase.GetFileName().Substring(0, sheetSetDatabase.GetFileName().LastIndexOf("\\"));

                // Set the default values of the sheet set
                //SetSheetSetDefaults(sheetSetDatabase, "CP318-4", "AU2009 Sheet Set Object Demo", sheetSetFolder, "C:\\Datasets\\CP318-4\\CP318-4.dwt", "Sheet");
                SetSheetSetDefaults(sheetSetDatabase, "Expedia Sheet Set", "ABF Sheet Set Object Demo", sheetSetFolder, @"C:\Users\rhale\Documents\AutoCAD Sheet Sets\ABFStylesSS.dwt", "Sheet");

                // Create a sheet set property
                SetCustomProperty(sheetSet, "Project Approved By", "Erin Tasche", PropertyFlags.CUSTOM_SHEETSET_PROP);

                // Create sheet properties
                //SetCustomProperty(sheetSet, "Checked By", "LAA", PropertyFlags.CUSTOM_SHEET_PROP);

                //SetCustomProperty(sheetSet, "Complete Percentage", "0%", PropertyFlags.CUSTOM_SHEET_PROP);

                SetCustomProperty(sheetSet, "Version #", versionNumber, PropertyFlags.CUSTOM_SHEET_PROP);

                SetCustomProperty(sheetSet, "Version Issue Date", versionIssueDate, PropertyFlags.CUSTOM_SHEET_PROP);


                //AddSheet(sheetSetDatabase, "Title Page", "Project Title Page", "Title Page", "T1");

                // Create two new subsets
                AcSmSubset subset = default(AcSmSubset);
                //subset = CreateSubset(sheetSetDatabase, "Plans", "Building Plans", "", "C:\\Datasets\\CP318-4\\CP318-4.dwt", "Sheet", false);
                subset = CreateSubset(sheetSetDatabase, "Submittals", "Project Submittals", "", @"C:\Users\Robert\Documents\AutoCAD Sheet Sets\ABFStylesSS.dwt", "Sheet", false);

                //subset = CreateSubset(sheetSetDatabase, "Elevations", "Building Elevations", "", "C:\\Datasets\\CP318-4\\CP318-4.dwt", "Sheet", true);
                subset = CreateSubset(sheetSetDatabase, "As Builts", "Project As Builts", "", @"C:\Users\Robert\Documents\AutoCAD Sheet Sets\ABFStylesSS.dwt", "Sheet", true);

                // Add a sheet property
                //SetCustomProperty(sheetSet, "Drafted By", "KMA", PropertyFlags.CUSTOM_SHEET_PROP);

                // Add a subset property
                SetCustomProperty(sheetSet, "Count", "0", PropertyFlags.CUSTOM_SHEETSET_PROP);

                // Sync the properties of the sheet set with the sheets and subsets
                SyncProperties(sheetSetDatabase);

                // Unlock the database
                LockDatabase(ref sheetSetDatabase, false);
            }
            else
            {
                // Display error message
                MessageBox.Show("Sheet set could not be opened for write.");
            }

            // Close the sheet set
            sheetSetManager.Close(sheetSetDatabase);
        }
        public void CreateSheetSet_AddCustomProperty()
        {
            // Get a reference to the Sheet Set Manager object
            IAcSmSheetSetMgr sheetSetManager = new AcSmSheetSetMgr();

            // Create a new sheet set file
            //AcSmDatabase sheetSetDatabase = sheetSetManager.CreateDatabase("C:\\Datasets\\CP318-4\\CP318-4.dst", "", true);
            //AcSmDatabase sheetSetDatabase = sheetSetManager.CreateDatabase("C:\\Datasets\\CP318-4\\CP318-4.dst", "", true);
            //AcSmDatabase sheetSetDatabase = sheetSetManager.OpenDatabase(@"C:\Users\rhale\Documents\AutoCAD Sheet Sets\Expedia.dst", true);
            //AcSmDatabase sheetSetDatabase = sheetSetManager.(@"C:\Users\rhale\Documents\AutoCAD Sheet Sets\Expedia.dst", true);

            // Open a Sheet Set file
            AcSmDatabase sheetSetDatabase = default(AcSmDatabase);

            //sheetSetDatabase = sheetSetManager.OpenDatabase("C:\\Program Files\\AutoCAD 2010\\Sample\\Sheet Sets\\Architectural\\IRD Addition.dst", false);
            sheetSetDatabase = sheetSetManager.OpenDatabase(@"C:\Users\rhale\Documents\AutoCAD Sheet Sets\Expedia.dst", false);

            // Get the sheet set from the database
            AcSmSheetSet sheetSet = sheetSetDatabase.GetSheetSet();

            // Attempt to lock the database
            if (LockDatabase(ref sheetSetDatabase, true) == true)
            {
                // Get the folder the sheet set is stored in
                string sheetSetFolder = null;
                sheetSetFolder = sheetSetDatabase.GetFileName().Substring(0, sheetSetDatabase.GetFileName().LastIndexOf("\\"));

                // Set the default values of the sheet set
                SetSheetSetDefaults(sheetSetDatabase, "My Expedia Sheet Set", "A&B Fabricators Sheet Set Object Demo", sheetSetFolder, @"C:\Users\rhale\Documents\AutoCAD Sheet Sets\ABFStylesSS.dwt", "Sheet");

                // Create a sheet set property
                SetCustomProperty(sheetSet, "Project Approved By", "Erin Tasche", PropertyFlags.CUSTOM_SHEETSET_PROP);

                // Create sheet properties
                SetCustomProperty(sheetSet, "Checked By", "NK", PropertyFlags.CUSTOM_SHEET_PROP);

                SetCustomProperty(sheetSet, "Complete Percentage", "90%", PropertyFlags.CUSTOM_SHEET_PROP);

                SetCustomProperty(sheetSet, "Version #", "D", PropertyFlags.CUSTOM_SHEET_PROP);

                SetCustomProperty(sheetSet, "Version Issue Date", "08/29/19", PropertyFlags.CUSTOM_SHEET_PROP);

                //AddSheet(sheetSetDatabase, "Title Page", "Project Title Page", "Title Page", "T1");

                // Create two new subsets
                AcSmSubset subset = default(AcSmSubset);
                subset = CreateSubset(sheetSetDatabase, "Plans", "Building Plans", "", @"C:\Users\rhale\Documents\AutoCAD Sheet Sets\ABFStylesSS.dwt", "Sheet", false);

                //AddSheet(subset, "North Plan", "Northern section of building plan", "North Plan", "P1");

                subset = CreateSubset(sheetSetDatabase, "Elevations", "Building Elevations", "", @"C:\Users\rhale\Documents\AutoCAD Sheet Sets\ABFStylesSS.dwt", "Sheet", true);

                // Sync the properties of the sheet set with the sheets and subsets
                SyncProperties(sheetSetDatabase);

                // Unlock the database
                LockDatabase(ref sheetSetDatabase, false);
            }
            else
            {
                // Display error message
                MessageBox.Show("Sheet set could not be opened for write.");
            }

            // Close the sheet set
            sheetSetManager.Close(sheetSetDatabase);
        }
        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);
        }
Esempio n. 6
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);
        }