Author Topic: Modify system variable on a closed drawing ?  (Read 1633 times)

0 Members and 1 Guest are viewing this topic.

latour_g

  • Newt
  • Posts: 184
Modify system variable on a closed drawing ?
« on: May 13, 2020, 10:26:54 AM »
Hi there,

I have done a few things on closed drawings but I have never changed a system variable, specificaly Proxygraphics.  I have search to see if it's doable but found nothing.
So I'm asking here, is it doable to do so ?

Thnak you
« Last Edit: May 14, 2020, 08:52:14 AM by latour_g »

WOWENS

  • Newt
  • Posts: 59
Re: Modify system variable on a closed drawing ?
« Reply #1 on: May 27, 2020, 02:47:04 PM »
might give this a try

Code - vb.net: [Select]
  1. Private Sub test2(MyDwg As String)
  2.             If IsFileLocked(New IO.FileInfo(MyDwg)) = False Then
  3.                 Using db As New Database(False, True)
  4.                     db.ReadDwgFile(MyDwg, IO.FileShare.ReadWrite, False, "")
  5.  
  6.                     Dim workDb As Database = HostApplicationServices.WorkingDatabase
  7.  
  8.                     If HostApplicationServices.WorkingDatabase <> db Then
  9.                         HostApplicationServices.WorkingDatabase = db
  10.                     End If
  11.  
  12.                     Using MyTrans As Transaction = db.TransactionManager.StartTransaction()
  13.                         Try
  14.  
  15.                             If db.Orthomode = True Then
  16.                                 db.Orthomode = False
  17.                             Else
  18.                                 db.Orthomode = True
  19.                             End If
  20.  
  21.                             db.Saveproxygraphics = 0
  22.  
  23.                             MyTrans.Commit()
  24.                             db.SaveAs(MyDwg, DwgVersion.Current)
  25.                         Catch
  26.                             MyTrans.Abort()
  27.                             db.CloseInput(True)
  28.                             Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbCrLf + "Could Not Save Drawing " & MyDwg)
  29.                         Finally
  30.                             If HostApplicationServices.WorkingDatabase <> workDb Then
  31.                                 HostApplicationServices.WorkingDatabase = workDb
  32.                             End If
  33.                         End Try
  34.                     End Using
  35.                     db.Dispose()
  36.                 End Using
  37.             Else
  38.                 Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbCrLf + "Could Not Open Drawing " & MyDwg)
  39.             End If
  40.         End Sub
  41.  
  42.  
  43.         Private Function IsFileLocked(ByVal file As IO.FileInfo) As Boolean
  44.             Dim stream As IO.FileStream = Nothing
  45.  
  46.             Try
  47.                 stream = file.Open(IO.FileMode.Open, IO.FileAccess.ReadWrite, IO.FileShare.None)
  48.             Catch
  49.                 Return True
  50.             End Try
  51.  
  52.             If (Not (stream) Is Nothing) Then
  53.                 stream.Close()
  54.             End If
  55.  
  56.             Return False
  57.  
  58.         End Function


EDIT (John): Added code tags.
« Last Edit: May 27, 2020, 03:35:37 PM by John Kaul (Se7en) »

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Modify system variable on a closed drawing ?
« Reply #2 on: May 28, 2020, 01:43:33 PM »
As Wowens showed if is a variable stored in the drawing and should be a property of Database object then you will have to open it with ReadDwgFile.
For system wide variables you can edit with Application  object or directly edit registry which probably would not be ideal.


latour_g

  • Newt
  • Posts: 184
Re: Modify system variable on a closed drawing ?
« Reply #3 on: June 03, 2020, 03:00:23 PM »
Thanks to both of you ! I will try it soon and let you know i it'S work !