コード例 #1
0
        public static Object GetSheetSetMgr()
        {
            //get an instance of the sheet set manager object
            IAcSmSheetSetMgr ssMgr = new AcSmSheetSetMgr();

            return(ssMgr);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void CreateSheetSet()
        {
            // 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 pr = ed.GetFileNameForSave("Hello Nadia, Where would you would like to save the new Sheet Set?");

            PromptStringOptions pso = new PromptStringOptions("\nHello Nadia! \nWhat will be the name of the new Sheet Set?");

            pso.AllowSpaces = true;
            PromptResult prSheetSetName = ed.GetString(pso);

            PromptStringOptions psoDescription = new PromptStringOptions("\nHello Nadia! \nWhat will be the description of the new Sheet Set?");

            psoDescription.AllowSpaces = true;
            PromptResult prSheetSetDescription = ed.GetString(psoDescription);


            //pso.DefaultValue = @"C:\Users\Robert\Documents\AutoCAD Sheet Sets\Expedia.dst";
            //pso.UseDefaultValue = true;

            // works...

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

            // Create a new sheet set file
            //AcSmDatabase sheetSetDatabase = sheetSetManager.CreateDatabase(@"C:\Users\Robert\Documents\AutoCAD Sheet Sets\ExpediaSheetSetDemo.dst", "", true);
            AcSmDatabase sheetSetDatabase = sheetSetManager.CreateDatabase(pr.StringResult, "", true);

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

            // Attempt to lock the database
            if (LockDatabase(ref sheetSetDatabase, true) == true)
            {
                // Set the name and description of the sheet set
                //sheetSet.SetName("ExpediaSheetSetTest");
                sheetSet.SetName(prSheetSetName.StringResult);

                //sheetSet.SetDesc("Aluminum Bronze Fabricator's Sheet Set Object Demo");
                sheetSet.SetDesc(prSheetSetDescription.StringResult);

                // Unlock the database
                LockDatabase(ref sheetSetDatabase, false);

                // Return the name and description of the sheet set
                MessageBox.Show("Sheet Set Name: " + sheetSetDatabase.GetSheetSet().GetName() + "\nSheet Set Description: " + sheetSetDatabase.GetSheetSet().GetDesc());
            }
            else
            {
                // Display error message
                MessageBox.Show("Sheet set could not be opened for write.");
            }

            // Close the sheet set
            sheetSetManager.Close(sheetSetDatabase);
        }
コード例 #4
0
 public void CloseAll(bool doIt = true)
 {
     if (doIt)
     {
         IAcSmSheetSetMgr ssMgr = new AcSmSheetSetMgr();
         ssMgr.CloseAll();
     }
 }
コード例 #5
0
        public AcSmSheet GetSheetFromLayout(AcadObject pAcDbLayout)
        {
            IAcSmSheetSetMgr ssMgr = new AcSmSheetSetMgr();
            AcSmSheet        sheet;

            ssMgr.GetSheetFromLayout(pAcDbLayout, out sheet);
            return(sheet);
        }
コード例 #6
0
        public void Close(Database database)
        {
            IAcSmSheetSetMgr ssMgr     = new AcSmSheetSetMgr();
            AcSmDatabase     dbToClose = database.BaseObject;

            ssMgr.Close(dbToClose);
            dbToClose.Clear();
            dbToClose = null;
        }
コード例 #7
0
        public SheetSet GetParentSheetSet(string filename, string layoutname)
        {
            IAcSmSheetSetMgr ssMgr = new AcSmSheetSetMgr();
            AcSmSheetSet     sheetSet;

            ssMgr.GetParentSheetSet(filename, layoutname, out sheetSet);
            SheetSet output = new SheetSet(sheetSet);

            return(output);
        }
コード例 #8
0
        public void CreateSheetSet_WithSubset()
        {
            // 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 pr = ed.GetFileNameForSave("Hello Nadia, Where would you would like to save the new Sheet Set?");

            PromptStringOptions pso = new PromptStringOptions("\nHello Nadia! \nWhat will be the name of the new Sheet Set?");

            pso.AllowSpaces = true;
            PromptResult prSheetSetName = ed.GetString(pso);

            PromptStringOptions psoDescription = new PromptStringOptions("\nHello Nadia! \nWhat will be the description of the new Sheet Set?");

            psoDescription.AllowSpaces = true;
            PromptResult prSheetSetDescription = ed.GetString(psoDescription);

            // 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(pr.StringResult, "", true);

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

            // Attempt to lock the database
            if (LockDatabase(ref sheetSetDatabase, true) == true)
            {
                // Set the name and description of the sheet set
                sheetSet.SetName(prSheetSetName.StringResult);
                sheetSet.SetDesc(prSheetSetDescription.StringResult);

                // 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);

                // 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);
        }
コード例 #9
0
        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());
            }
        }
コード例 #10
0
        public void StepThroughOpenSheetSets()
        {
            // Get a reference to the Sheet Set Manager object
            IAcSmSheetSetMgr sheetSetManager = new AcSmSheetSetMgr();

            // Get the loaded databases
            IAcSmEnumDatabase enumDatabase = sheetSetManager.GetDatabaseEnumerator();

            // Get the first open database
            IAcSmPersist item = enumDatabase.Next();

            string customMessage = "";

            // If a database is open continue
            if ((item != null))
            {
                int count = 0;

                // Step through the database enumerator
                while ((item != null))
                {
                    // Append the file name of the open sheet set to the output string
                    customMessage = customMessage + "\n" + item.GetDatabase().GetFileName();

                    // Get the next open database and increment the counter
                    item  = enumDatabase.Next();
                    count = count + 1;
                }

                customMessage = "Sheet sets open: " + count.ToString() + customMessage;
            }
            else
            {
                customMessage = "No sheet sets are currently open.";
            }

            // Display the custom message
            MessageBox.Show(customMessage);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        public void Unregister(int cookie)
        {
            IAcSmSheetSetMgr ssMgr = new AcSmSheetSetMgr();

            ssMgr.Unregister(cookie);
        }
コード例 #14
0
        public int Register(IAcSmEvents eventHandler)
        {
            IAcSmSheetSetMgr ssMgr = new AcSmSheetSetMgr();

            return(ssMgr.Register(eventHandler));
        }
コード例 #15
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;

            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);
        }
コード例 #16
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);
        }