Author Topic: Saving your app settings to NOD  (Read 1101 times)

0 Members and 1 Guest are viewing this topic.

poncelet

  • Guest
Saving your app settings to NOD
« on: March 25, 2012, 06:17:54 AM »
Hello guys, i'm creating a class that saves the setting of my form app into the current dwg NOD. Have anyone done something similar? Is this the right way? Any suggestions? Thanks.

Code - vb.net: [Select]
  1.     Public Sub Create(ByVal dict As Dictionary(Of String, Control))
  2.  
  3.         Dim trans As Transaction = ed.Document.Database.TransactionManager.StartTransaction
  4.         Dim dLock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument
  5.  
  6.         Try
  7.  
  8.             Dim nod As DBDictionary = trans.GetObject(ed.Document.Database.NamedObjectsDictionaryId, OpenMode.ForRead)
  9.  
  10.             If Not nod.Contains("Yrion Settings") Then
  11.  
  12.                 nod.UpgradeOpen()
  13.                 Dim d As New DBDictionary
  14.                 nod.SetAt("Yrion Settings", d)
  15.                 trans.AddNewlyCreatedDBObject(d, True)
  16.  
  17.                 Dim list As New List(Of String)(dict.Keys)
  18.                 For Each str As String In list
  19.                     Dim data As ResultBuffer = New ResultBuffer(New TypedValue(DxfCode.Text, dict(str).Text))
  20.                     Dim xr As New Xrecord
  21.                     xr.Data = data
  22.                     d.SetAt(str, xr)
  23.                     trans.AddNewlyCreatedDBObject(xr, True)
  24.                 Next
  25.  
  26.             End If
  27.  
  28.             trans.Commit()
  29.  
  30.         Catch ex As Exception
  31.             ed.WriteMessage(vbLf & "A problem occurred because " & ex.Message & vbLf)
  32.         Finally
  33.             trans.Dispose()
  34.             dLock.Dispose()
  35.         End Try
  36.  
  37.     End Sub