.NET

.NET

Reply
Active Contributor
manoajco
Posts: 28
Registered: ‎08-22-2013
Message 1 of 6 (234 Views)

Identify the respective CTB file linked to the autocad drawing file

234 Views, 5 Replies
12-09-2013 09:56 PM

I have linked a CTB file to the drawing file in autocad. Now i wanna convert the dwg to pdf using autocad api.I need to use the respective CTB file linked to the dwg while coverting.If I have a set of CTB files with me, how can I identify the respective CTB file using API in .NET?

*Expert Elite*
norman.yuan
Posts: 987
Registered: ‎04-27-2009
Message 2 of 6 (204 Views)

Re: Identify the respective CTB file linked to the autocad drawing file

12-10-2013 09:39 AM in reply to: manoajco

CTB file (plot style sheet) used in a drawing file is associated to layouts in the drawing. So, if you want to identify what CTBs are used in a drawing file, you need to loop through all layouts in a drawing and find Layout.CurrentStyleSheet property, which is a string value of the CTB name.

 

Hope this answers your question.

Mentor
SENL1362
Posts: 167
Registered: ‎07-20-2011
Message 3 of 6 (195 Views)

Re: Identify the respective CTB file linked to the autocad drawing file

12-10-2013 12:17 PM in reply to: norman.yuan
Don't forget Named Plot Styles (PlotSettings). The CTB files referenced by the PlotSettings may not be visible or used but still are referenced.

Active Contributor
manoajco
Posts: 28
Registered: ‎08-22-2013
Message 4 of 6 (188 Views)

Re: Identify the respective CTB file linked to the autocad drawing file

12-10-2013 08:35 PM in reply to: norman.yuan
Thank you very much for your replies. Since i am a new bie in Autocad, if you could help with some C# code to loop through all the layouts in a particular document, that would be very helpful. Mean time i will try my very best to find a way to crack it.
Active Contributor
manoajco
Posts: 28
Registered: ‎08-22-2013
Message 5 of 6 (184 Views)

Re: Identify the respective CTB file linked to the autocad drawing file

12-10-2013 08:37 PM in reply to: SENL1362

I did not really get what you meant. If you could explain it, that would be wonderful. Thank you very much for your effort.

Mentor
SENL1362
Posts: 167
Registered: ‎07-20-2011
Message 6 of 6 (176 Views)

Re: Identify the respective CTB file linked to the autocad drawing file

12-10-2013 11:29 PM in reply to: manoajco
           [CommandMethod("LPS")]
            public static void ListPlotSettingS()
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                Editor ed = doc.Editor;

                
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    PlotSettingsValidator plotSettingsValidator = PlotSettingsValidator.Current;

                    DBDictionary plotSettingsDict = (DBDictionary)tr.GetObject(db.PlotSettingsDictionaryId, OpenMode.ForRead);
                    foreach (DBDictionaryEntry plotSettingsEntry in plotSettingsDict)
                    {
                        PlotSettings plotSettings = (PlotSettings)tr.GetObject(plotSettingsEntry.Value, OpenMode.ForWrite);
                        plotSettingsValidator.RefreshLists(plotSettings);

                        ed.WriteMessage("PlotSettingsName: {0}\n", plotSettings.PlotSettingsName);
                        ed.WriteMessage("\t ConfigurationName: {0}\n", plotSettings.PlotConfigurationName);
                        ed.WriteMessage("\t LocaleMediaName: {0} ({1})\n", plotSettingsValidator.GetLocaleMediaName(plotSettings, plotSettings.CanonicalMediaName), plotSettings.CanonicalMediaName);
                        ed.WriteMessage("\t PlotType: {0}\n", plotSettings.PlotType);
                        ed.WriteMessage("\t PaperUnits: {0}\n", plotSettings.PlotPaperUnits);
                        ed.WriteMessage("\t PaperSize: {0}\n", plotSettings.PlotPaperSize);
                        ed.WriteMessage("\t PaperMargins: {0}\n", plotSettings.PlotPaperMargins);
                        ed.WriteMessage("\t Centered: {0}\n", plotSettings.PlotCentered);
                        ed.WriteMessage("\t Origin: {0}\n", plotSettings.PlotOrigin);
                        ed.WriteMessage("\t Rotation: {0}\n", plotSettings.PlotRotation);
                        if (plotSettings.UseStandardScale)
                            ed.WriteMessage("\t StdScale: {0}\n", plotSettings.StdScale);
                        else
                            ed.WriteMessage("\t CustomScale: {0}\n", plotSettings.CustomPrintScale);

                        ed.WriteMessage("\t Transparency: {0}\n", plotSettings.PlotTransparency);
                        ed.WriteMessage("\t ViewportBorders: {0}\n", plotSettings.PlotViewportBorders);
                        ed.WriteMessage("\t PrintLineweights: {0}\n", plotSettings.PrintLineweights);
                        ed.WriteMessage("\t StyleSheet: {0}\n", plotSettings.CurrentStyleSheet);
                        ed.WriteMessage("\t PlotStyles: {0}\n", plotSettings.PlotPlotStyles);
                        ed.WriteMessage("\t ScaleLineweights: {0}\n", plotSettings.ScaleLineweights);


                    }
                }


            }

 

           [CommandMethod("LLS")]
            public static void ListLayoutPlotSettings()
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                Editor ed = doc.Editor;
                LayoutManager layoutManager = LayoutManager.Current;
                PlotSettingsValidator plotSettingsValidator = PlotSettingsValidator.Current;

 
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {

                    DBDictionary layoutDict = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
                    DBDictionary plotSettingsDict = (DBDictionary)tr.GetObject(db.PlotSettingsDictionaryId, OpenMode.ForRead);
                    foreach (DBDictionaryEntry layoutEntry in layoutDict)
                    {
                        Layout layout = (Layout)tr.GetObject(layoutEntry.Value, OpenMode.ForRead);
                        if (layout.ModelType)
                            continue;
                        ed.WriteMessage("LayoutName: {0}\n", layout.LayoutName);

                        layoutManager.CurrentLayout = layout.LayoutName;
                        PlotSettings plotSettings = new PlotSettings(layout.ModelType);
                        plotSettings.CopyFrom(layout);
                        plotSettingsValidator.RefreshLists(plotSettings);

                        ed.WriteMessage("PlotSettingsName: {0}\n", plotSettings.PlotSettingsName);
                        ed.WriteMessage("\t ConfigurationName: {0}\n", plotSettings.PlotConfigurationName);
                        ed.WriteMessage("\t LocaleMediaName: {0} ({1})\n", plotSettingsValidator.GetLocaleMediaName(plotSettings, plotSettings.CanonicalMediaName), plotSettings.CanonicalMediaName);
                        ed.WriteMessage("\t PlotType: {0}\n", plotSettings.PlotType);
                        ed.WriteMessage("\t PaperUnits: {0}\n", plotSettings.PlotPaperUnits);
                        ed.WriteMessage("\t PaperSize: {0}\n", plotSettings.PlotPaperSize);
                        ed.WriteMessage("\t PaperMargins: {0}\n", plotSettings.PlotPaperMargins);
                        ed.WriteMessage("\t Centered: {0}\n", plotSettings.PlotCentered);
                        ed.WriteMessage("\t Origin: {0}\n", plotSettings.PlotOrigin);
                        ed.WriteMessage("\t Rotation: {0}\n", plotSettings.PlotRotation);
                        if (plotSettings.UseStandardScale)
                            ed.WriteMessage("\t StdScale: {0}\n", plotSettings.StdScale);
                        else
                            ed.WriteMessage("\t CustomScale: {0}\n", plotSettings.CustomPrintScale);

                        ed.WriteMessage("\t Transparency: {0}\n", plotSettings.PlotTransparency);
                        ed.WriteMessage("\t ViewportBorders: {0}\n", plotSettings.PlotViewportBorders);
                        ed.WriteMessage("\t PrintLineweights: {0}\n", plotSettings.PrintLineweights);
                        ed.WriteMessage("\t StyleSheet: {0}\n", plotSettings.CurrentStyleSheet);
                        ed.WriteMessage("\t PlotStyles: {0}\n", plotSettings.PlotPlotStyles);
                        ed.WriteMessage("\t ScaleLineweights: {0}\n", plotSettings.ScaleLineweights);

                    }
                    tr.Commit();
                }
            }

 Clipboard-1.png

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.