Author Topic: Visual Styles  (Read 447 times)

0 Members and 1 Guest are viewing this topic.

FriendFromArea51

  • Swamp Rat
  • Posts: 579
  • Mars sucks!
Visual Styles
« on: February 02, 2017, 05:05:59 pm »
Anyone know why when I try to change a viewport to "2DWirefame" below it is actually creating a new visual style for the viewport called "$0$2dwireframe" and then "$1$2dwireframe", consecutively for each layout in the drawing?

Code - C#: [Select]
  1.              DBDictionary dict = t.GetObject(Application.DocumentManager.MdiActiveDocument.Database.VisualStyleDictionaryId, OpenMode.ForRead) as DBDictionary;
  2.                        vp.VisualStyleId = dict.GetAt("2dwireframe");
  3.                        //end setting the style***************************************************************
  4.  
- Area51Visitor

kdub

  • SuperMod
  • Swamp Rat
  • Posts: 931
  • class keyThumper<T>:ILazy<T>
Re: Visual Styles
« Reply #1 on: February 02, 2017, 07:30:41 pm »
What happens when you try "2dWireframe" or "Shaded"  <<== note capitalisation.

also,
Have a look at

Autodesk.AutoCAD.Internal.Utils.

public static ObjectId visualStyleId(string visualStyleName);
and
public static void SetCurrentViewportVisualStyle(ObjectId visualStyleId);

public static ObjectId GetCurrentViewportVisualStyleId();
and
public static string visualStyleName(ObjectId id);
« Last Edit: February 02, 2017, 07:35:59 pm by kdub »
called Kerry in my other life

Sometimes the question is more important than the answer.

FriendFromArea51

  • Swamp Rat
  • Posts: 579
  • Mars sucks!
Re: Visual Styles
« Reply #2 on: February 03, 2017, 05:19:32 pm »
What happens when you try "2dWireframe" or "Shaded"  <<== note capitalisation.

also,
Have a look at

Autodesk.AutoCAD.Internal.Utils.

public static ObjectId visualStyleId(string visualStyleName);
and
public static void SetCurrentViewportVisualStyle(ObjectId visualStyleId);

public static ObjectId GetCurrentViewportVisualStyleId();
and
public static string visualStyleName(ObjectId id);

Thanks! Pretty nuts. I've tried every form of capitalization i could:

2D Wireframe
2dWireframe
2dwireframe
2DWireframe

one of the error, the others insist on adding the prefixes.  I'll take a look a the various other options you show.

- Area51Visitor

kdub

  • SuperMod
  • Swamp Rat
  • Posts: 931
  • class keyThumper<T>:ILazy<T>
Re: Visual Styles
« Reply #3 on: February 03, 2017, 08:20:52 pm »
This works for me :
Code - C#: [Select]
  1. using System;
  2. using Autodesk.AutoCAD.Runtime;
  3. using Autodesk.AutoCAD.ApplicationServices;
  4. using Autodesk.AutoCAD.DatabaseServices;
  5. using Autodesk.AutoCAD.Geometry;
  6. using Autodesk.AutoCAD.EditorInput;
  7. using AcadApp = Autodesk.AutoCAD.ApplicationServices.Core.Application;
  8.  
  9. [assembly: CommandClass(typeof(VisualStyleTest.MyCommands))]
  10.  
  11. namespace VisualStyleTest
  12. {
  13.    public class MyCommands
  14.    {
  15.        [CommandMethod("VST1", CommandFlags.Modal)]
  16.        static public void SetVisualStyleTest1()
  17.        {
  18.            var doc = AcadApp.DocumentManager.MdiActiveDocument;
  19.            var ed  = doc.Editor;
  20.            var db  = doc.Database;
  21.  
  22.            using (var tr = db.TransactionManager.StartTransaction())
  23.            {
  24.                var vt   = (ViewportTable) tr.GetObject(db.ViewportTableId, OpenMode.ForRead);
  25.                var vtr  = (ViewportTableRecord) tr.GetObject(vt["*Active"], OpenMode.ForWrite);
  26.                var dict = (DBDictionary) tr.GetObject(db.VisualStyleDictionaryId, OpenMode.ForRead);
  27.                vtr.VisualStyleId = dict.GetAt("2dWireFrame");
  28.                tr.Commit();
  29.            }
  30.            ed.UpdateTiledViewportsFromDatabase();
  31.        }
  32.    }
  33. }
  34.  
called Kerry in my other life

Sometimes the question is more important than the answer.

kdub

  • SuperMod
  • Swamp Rat
  • Posts: 931
  • class keyThumper<T>:ILazy<T>
Re: Visual Styles
« Reply #4 on: February 03, 2017, 08:38:55 pm »
Ditto :

Code - C#: [Select]
  1. using System;
  2. using Autodesk.AutoCAD.Runtime;
  3. using Autodesk.AutoCAD.ApplicationServices;
  4. using Autodesk.AutoCAD.DatabaseServices;
  5. using Autodesk.AutoCAD.Geometry;
  6. using Autodesk.AutoCAD.EditorInput;
  7. using AcadApp = Autodesk.AutoCAD.ApplicationServices.Core.Application;
  8. using AcadInt = Autodesk.AutoCAD.Internal;
  9. [assembly: CommandClass(typeof(VisualStyleTest.MyCommands))]
  10.  
  11. namespace VisualStyleTest
  12. {
  13.    public class MyCommands
  14.    {
  15.        [CommandMethod("VST2", CommandFlags.Modal)]
  16.        static public void SetVisualStyleTest2()
  17.        {
  18.            ObjectId visualStyleId = AcadInt.Utils.visualStyleId("Shaded");
  19.            AcadInt.Utils.SetCurrentViewportVisualStyle(visualStyleId);
  20.  
  21.        }
  22.    }
  23. }
  24.  
called Kerry in my other life

Sometimes the question is more important than the answer.

FriendFromArea51

  • Swamp Rat
  • Posts: 579
  • Mars sucks!
Re: Visual Styles
« Reply #5 on: February 06, 2017, 02:19:50 pm »
This works for me :
Code - C#: [Select]
  1. using System;
  2. using Autodesk.AutoCAD.Runtime;
  3. using Autodesk.AutoCAD.ApplicationServices;
  4. using Autodesk.AutoCAD.DatabaseServices;
  5. using Autodesk.AutoCAD.Geometry;
  6. using Autodesk.AutoCAD.EditorInput;
  7. using AcadApp = Autodesk.AutoCAD.ApplicationServices.Core.Application;
  8.  
  9. [assembly: CommandClass(typeof(VisualStyleTest.MyCommands))]
  10.  
  11. namespace VisualStyleTest
  12. {
  13.    public class MyCommands
  14.    {
  15.        [CommandMethod("VST1", CommandFlags.Modal)]
  16.        static public void SetVisualStyleTest1()
  17.        {
  18.            var doc = AcadApp.DocumentManager.MdiActiveDocument;
  19.            var ed  = doc.Editor;
  20.            var db  = doc.Database;
  21.  
  22.            using (var tr = db.TransactionManager.StartTransaction())
  23.            {
  24.                var vt   = (ViewportTable) tr.GetObject(db.ViewportTableId, OpenMode.ForRead);
  25.                var vtr  = (ViewportTableRecord) tr.GetObject(vt["*Active"], OpenMode.ForWrite);
  26.                var dict = (DBDictionary) tr.GetObject(db.VisualStyleDictionaryId, OpenMode.ForRead);
  27.                vtr.VisualStyleId = dict.GetAt("2dWireFrame");
  28.                tr.Commit();
  29.            }
  30.            ed.UpdateTiledViewportsFromDatabase();
  31.        }
  32.    }
  33. }
  34.  

Thanks Kdub. I think since I'm creating the viewports in a newdb / outside drawing is why I'm having trouble. I essentially added this at the code to make sure that the viewports are set to the 2dWireframe style before saving the database.  Now I just need to purge out the old ones lol...strange stuff.
- Area51Visitor