Problem removing CAD standards programatically (VB.NET)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there,
Here is the story.
I have a drawing with say 3 CAD standards associated.
Given the full file name (including path), I'm able to retreive the corresponding Xrecord and remove it from the dicstionary.
Then, if I open the configure Standards dialog, I only see the 2 standards left
so far so good.
The problems is that when I close the DWG, saving it of course, then reopen it and open the configure Standards dialog. They're all gone, including the 2 standards that should still be there.
I guess I do something wring but I have no idea what ????????
Here is my code:
Private Sub DetachStandard(_filename as String) Dim tr As Transaction = Nothing Dim db As Database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database Dim sPath As String = "" Dim lock As Autodesk.AutoCAD.ApplicationServices.DocumentLock = Nothing Try ' 1st, we lock the database as we're going to modify it lock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument() ' We start the transaction tr = db.TransactionManager.StartTransaction ' Getting the database dictionary Dim nod As DBDictionary = tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite, False) ' Getting AcStStandard in the dictionary. If none are present, it will be handled in the catch Dim id As ObjectId = nod.Item("AcStStandard") ' Getting standards dict Dim dict As DBDictionary = tr.GetObject(id, OpenMode.ForWrite, False) ' Looping thru standards list For Each entry As DictionaryEntry In dict sPath = "" Dim oId As ObjectId = entry.Value Dim record As Xrecord = tr.GetObject(oId, OpenMode.ForWrite, False) Dim arrData As Array = record.Data.AsArray Dim tValue As TypedValue = arrData(0) ' Getting the path of the DWS file If File.Exists(tValue.Value) Then sPath = tValue.Value.ToString Else Try sPath = HostApplicationServices.Current.FindFile(New FileInfo(tValue.Value.ToString).Name, db, FindFileHint.Default) Catch End Try End If If Not String.IsNullOrEmpty(sPath) Then ' Path has been resolved. If String.Compare(sPath, _filename, True) = 0 Then ' This is the one to remove record.Erase() Else ' This is not the one to remove, doing nothing End If Else ' Path not resolved. File not found, nothing to do End If Next Catch ex As System.Exception If String.Compare(ex.Message, "eKeyNotFound", True) = 0 Then ' No CAD standards in this file Return End If Throw ex Finally If Not lock Is Nothing Then lock.Dispose() 'Unlocking the database as we're done Try If Not tr Is Nothing Then tr.Commit() ' Commitin the transaction End If Catch ' Ignoring any error when commiting the transaction End Try End Try End Sub
Any help would be greatly appreciated
Link copied