We need to iterate through the visual style dictionary of the current database from time to time. Here is some succinct and good code in C# to do so.
[CommandMethod("VisualStyleIterator")]
public static void VisualStyleIterator_Method()
{
Database database = HostApplicationServices.WorkingDatabase;
using (Transaction transaction = database.TransactionManager.StartTransaction())
{
DBDictionary dbDictionary = (DBDictionary)transaction.GetObject(database.VisualStyleDictionaryId, OpenMode.ForRead);
foreach (DBDictionaryEntry dictEntry in dbDictionary)
{
DBVisualStyle entry = (DBVisualStyle)transaction.GetObject(dictEntry.Value, OpenMode.ForRead);
//TODO: Access to the entry object
MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nVisual style name: {0}", entry.Name));
}
transaction.Commit();
}
}
If the command is run, something like the following may be printed out to the command line window.
Command: VisualStyleIterator
Visual style name: 2dWireframe
Visual style name: 3D Hidden
Visual style name: 3dWireframe
Visual style name: Basic
Visual style name: Brighten
Visual style name: ColorChange
Visual style name: Conceptual
Visual style name: Dim
Visual style name: EdgeColorOff
Visual style name: Facepattern
Visual style name: Flat
Visual style name: FlatWithEdges
Visual style name: Gouraud
Visual style name: GouraudWithEdges
Visual style name: Hidden
Visual style name: JitterOff
Visual style name: Linepattern
Visual style name: OverhangOff
Visual style name: Realistic
Visual style name: Shaded
Visual style name: Shaded with edges
Visual style name: Shades of Gray
Visual style name: Sketchy
Visual style name: Thicken
Visual style name: Wireframe
Visual style name: X-Ray
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides various wizards, coders, and widgets to help program AutoCAD addins in C#, VB.NET or even C++/CLI.
is there a way in C# to capture the current visualstyle so i can use it later to reset the visualstyle back.
Posted by: McDiver | 03/23/2015 at 09:33 AM
Hi McDiver, the Viewport.VisualStyleId Property should be what you are looking for. Since visual style is viewport dependant instead of database or document, no system variable is used to store the current visual style setting. The Database.ViewportTableId can give you the view port table then you can retrieve the *Active viewport from it. In case you’d like to get the display name of the visual style as shown by the UI, you can open the DBVisualStyle and get its Name as demonstrated in the post here.
Posted by: Spiderinnet1 | 03/24/2015 at 09:17 PM