.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Identify the respective CTB file linked to the autocad drawing file

5 REPLIES 5
Reply
Message 1 of 6
wrenchinternal
979 Views, 5 Replies

Identify the respective CTB file linked to the autocad drawing file

wrenchinternal
Enthusiast
Enthusiast

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?

0 Likes

Identify the respective CTB file linked to the autocad drawing file

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?

5 REPLIES 5
Message 2 of 6

norman.yuan
Mentor
Mentor

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.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes

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.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 6
SENL1362
in reply to: norman.yuan

SENL1362
Advisor
Advisor
Don't forget Named Plot Styles (PlotSettings). The CTB files referenced by the PlotSettings may not be visible or used but still are referenced.

0 Likes

Don't forget Named Plot Styles (PlotSettings). The CTB files referenced by the PlotSettings may not be visible or used but still are referenced.

Message 4 of 6

wrenchinternal
Enthusiast
Enthusiast
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.
0 Likes

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.
Message 5 of 6
wrenchinternal
in reply to: SENL1362

wrenchinternal
Enthusiast
Enthusiast

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

0 Likes

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

Message 6 of 6
SENL1362
in reply to: wrenchinternal

SENL1362
Advisor
Advisor
           [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

0 Likes

           [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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report