List all available plot styles with .NET API

List all available plot styles with .NET API

varshaauti27
Advocate Advocate
911 Views
8 Replies
Message 1 of 9

List all available plot styles with .NET API

varshaauti27
Advocate
Advocate

Hi, 

I am looking for method or way to retrieve all available plot styles. There is PlotStyleNameDictionaryId gives plot styles that are currently being used. But looking for a method to list ALL of the available plot styles, including those that haven't yet been used in the drawing?

0 Likes
Accepted solutions (2)
912 Views
8 Replies
Replies (8)
Message 2 of 9

hippe013
Advisor
Advisor

You need to be able to read the actual style table file (.stb). I use PiaNO for this. 

 

It can be found here: 

 

https://github.com/phusband/PiaNO

0 Likes
Message 3 of 9

varshaauti27
Advocate
Advocate

Is it possible to read style table file (.stb) with API itself instead of third-party dll?

0 Likes
Message 4 of 9

Jeff_M
Consultant
Consultant
        [CommandMethod("ListAllPlotStyles")]
        public void listallplotstyles()
        {
            dynamic comAcad = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
            string[] stylePaths = comAcad.Preferences.Files.PrinterStyleSheetPath.Split(';');
            var theList = "";
            //if there are multiple paths, will need to loop through those as well
            foreach (var fileName in Directory.GetFiles(stylePaths[0]))
            {
                if (fileName.EndsWith("tb"))
                    theList += theList == "" ? fileName : "\n" + fileName;
            }
            if (theList == "")
                return;
            Application.ShowAlertDialog(theList.ToString());
        }
Jeff_M, also a frequent Swamper
EESignature
Message 5 of 9

varshaauti27
Advocate
Advocate

Thanks Jeff for looking into this issue.

 

But I don't need .stb file list.  I am looking for all available plot style list.

varshaauti27_0-1670876471901.png

Refer attached image, Where I have selected "acad.stb" and "Autodesk-Color.stb" as plot style table which gives me plot styles associated with that selected style table. 

 

I am looking for way to retrieve all available plot styles. I think there might be way to read plot style table and grab plot styles. Not sure at this moment if it's possible with API

Any workaround to retrieve all plot styles available is appreciated. Thanks a lot! 

 

0 Likes
Message 6 of 9

Jeff_M
Consultant
Consultant
Accepted solution

Ah, completely misread the request. Why not use the application @hippe013 suggested? It has a free use license and the source code is included so you would be able to combine that dll with yours. I'm not seeing anything built-in to the Autodesk API's.

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 7 of 9

hippe013
Advisor
Advisor
Accepted solution

There isn't anything the AutoCAD API for reading .ctb or .stb files. PiaNO is very easy to use. And as @Jeff_M said, the source code is available if you wanted to include it in your own dll. I just compiled the dll as it was presented and include it as a reference in my projects that require reading an .stb file. Here is a quick example: 

Public Shared Function GetPlotStyleNames(path As String, pStyleMode As Integer) As StringCollection
   Dim styleNames As New StringCollection
   If pStyleMode = 0 Then
      'Named Plot Styles
      Dim plotStyleTable As New PlotStyleTable(path)
      For Each style As PlotStyle In plotStyleTable.PlotStyles
         styleNames.Add(style.Name)
      Next
   ElseIf pStyleMode = 1 Then
      'Color Dependent Styles
      Dim colorTable As New ColorDependentPlotStyleTable(path)
      For Each style As PlotStyle In colorTable.PlotStyles
         styleNames.Add(style.Name)
      Next
   End If
   Return styleNames
End Function

 

 

0 Likes
Message 8 of 9

varshaauti27
Advocate
Advocate

Thanks Jeff, This code snippet helps me to retrieve .stb and .ctb files and using PiaNo.dll I am able to find Plot styles associated with those file.

0 Likes
Message 9 of 9

varshaauti27
Advocate
Advocate

@hippe013 Thank you so much for looking into this issue and providing source code. I am able to retrieve Plot styles using PiaNo.dll

0 Likes