Author Topic: Visual Styles  (Read 2808 times)

0 Members and 1 Guest are viewing this topic.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
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.  

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2124
  • 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
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
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.


kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2124
  • 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
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2124
  • 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
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
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.