Author Topic: Set System Variable  (Read 2583 times)

0 Members and 1 Guest are viewing this topic.

GumbyCAD

  • Newt
  • Posts: 84
Set System Variable
« on: August 04, 2014, 09:47:01 PM »
On previous Post it was discussed on how to set DIMSCALE.

http://www.theswamp.org/index.php?topic=39250.0

The final reponse said:

Quote
No, it doesn't. It will depend entirely on the context of where it's being called from.

Can anyone explain further as to different senarios would differ and to how this would be done?
i.e.  Modal Dialog, Modeless Dialog, Non Dialog etc

Stephan

GumbyCAD

  • Newt
  • Posts: 84
Re: Set System Variable
« Reply #1 on: August 05, 2014, 10:47:22 PM »
The reason I ask is that if I run the following code it works on all varaibles so far except for DIMSTYLE.

I get eInvalidnput as marked below.

Code - Visual Basic: [Select]
  1.     Public Sub SetSysVariable(ByVal VariableName As String, ByVal Value As Object)
  2.  
  3.         Dim Doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
  4.  
  5.         Using DocKock As DocumentLock = Doc.LockDocument
  6.             Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable(VariableName, Value) '<-- Error Here
  7.        End Using
  8.  
  9.     End Sub
  10.  

Thanks in advance.
Stephan

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Set System Variable
« Reply #2 on: August 05, 2014, 10:59:14 PM »

That would be because DIMSTYLE is ReadOnly
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

GumbyCAD

  • Newt
  • Posts: 84
Re: Set System Variable
« Reply #3 on: August 05, 2014, 11:05:08 PM »
Oops.

How would you suggest to set the Dimstyle?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Set System Variable
« Reply #4 on: August 05, 2014, 11:06:40 PM »
Hi Stephan,
Try this ( or part of it)

http://adndevblog.typepad.com/autocad/2012/04/creating-a-new-dimension-style-and-make-it-as-current.html


added:
Sorry  :evil:
Most of the good stuff is in C#



kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

GumbyCAD

  • Newt
  • Posts: 84
Re: Set System Variable
« Reply #5 on: August 05, 2014, 11:18:24 PM »
Too funny, googled it and found that one too.

Thanks Kerry

End Solution

Code - Visual Basic: [Select]
  1.     Public Sub SetDimStyleCurrent(DimStyleName As String)
  2.  
  3.         Dim doc As Document = Application.DocumentManager.MdiActiveDocument
  4.         Dim db As Database = doc.Database
  5.  
  6.         Using DockLock As DocumentLock = doc.LockDocument
  7.  
  8.             Using tr As Transaction = doc.TransactionManager.StartTransaction()
  9.  
  10.                 Dim dst As DimStyleTable = DirectCast(tr.GetObject(db.DimStyleTableId, OpenMode.ForRead), DimStyleTable)
  11.                 Dim dimId As ObjectId = ObjectId.Null
  12.  
  13.                 dimId = dst(DimStyleName)
  14.  
  15.                 Dim dstr As DimStyleTableRecord = DirectCast(tr.GetObject(dimId, OpenMode.ForRead), DimStyleTableRecord)
  16.  
  17.                 db.Dimstyle = dstr.ObjectId
  18.                 db.SetDimstyleData(dstr)
  19.  
  20.                 tr.Commit()
  21.  
  22.             End Using
  23.  
  24.         End Using
  25.  
  26.     End Sub
  27.  

Code - C: [Select]
  1.         public static void SetDimStyleCurrent(string DimStyleName)
  2.         {
  3.             // Establish connections to the document and its database
  4.             Document doc = Application.DocumentManager.MdiActiveDocument;
  5.             Database db = doc.Database;
  6.  
  7.             // Establish a transaction
  8.             using (Transaction tr = doc.TransactionManager.StartTransaction())
  9.             {
  10.                 DimStyleTable dst = (DimStyleTable)tr.GetObject(db.DimStyleTableId, OpenMode.ForRead);
  11.                 ObjectId dimId = ObjectId.Null;
  12.  
  13.                 dimId = dst[DimStyleName];
  14.  
  15.                 DimStyleTableRecord dstr = (DimStyleTableRecord)tr.GetObject(dimId, OpenMode.ForRead);
  16.                
  17.                 db.Dimstyle = dstr.ObjectId;
  18.                 db.SetDimstyleData(dstr);                
  19.  
  20.                 tr.Commit();
  21.             }
  22.         }
  23.  

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Set System Variable
« Reply #6 on: August 06, 2014, 01:08:09 AM »
Stephan,
Sometime you may want to check for the existence of the DimStyle in the table before you try to set it current.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

GumbyCAD

  • Newt
  • Posts: 84
Re: Set System Variable
« Reply #7 on: August 06, 2014, 02:00:13 AM »
You are right.  But i my case it will only have available Styles to set.

BlackBox

  • King Gator
  • Posts: 3770
Re: Set System Variable
« Reply #8 on: August 06, 2014, 07:19:54 AM »
Be sure to add these to the Library Routines, as they may help others as well.  :wink:

Cheers
"How we think determines what we do, and what we do determines what we get."