locking layers in a routine with a new database not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Awhile back I was trying to get some stuff to work & somewhere stumbled upon some code that created a new database object from a filename. I didn't really understand it, but it seemed to work, so fine.
Now I'm trying to add some features to my routine & the following code is not working:
Shared Function LayerLockDB(ByVal dwgFileName As String, ByVal LayerName As String) As Boolean
LayerLockDB = False
Dim acLayerTable As LayerTable
Dim acLyrTblRec As LayerTableRecord
Dim myLayerId As ObjectId
Dim myDb As New Database(False, True)
myDb.ReadDwgFile(dwgFileName, FileOpenMode.OpenForReadAndAllShare, False, "")
Using acTrans As Transaction = myDb.TransactionManager.StartTransaction
Try ' verify layer exists - If Layer Exist recover LayerID
acLayerTable = CType(acTrans.GetObject(myDb.LayerTableId, OpenMode.ForRead, True, True), LayerTable)
myLayerId = acLayerTable.Item(LayerName)
If myLayerId.IsErased Then ' If Deleted, Recover Layer
acLayerTable.UpgradeOpen()
acLayerTable.Item(LayerName).GetObject(OpenMode.ForWrite, True, True).Erase(False)
End If
Catch ex As Exception ' Layer Doesn't Exist: Create it
CreateLayerDB(dwgFileName, LayerName, 7)
acLayerTable = CType(acTrans.GetObject(myDb.LayerTableId, OpenMode.ForRead, False), LayerTable) ' Recover LayerID of newly created Layer
End Try
acLyrTblRec = acTrans.GetObject(acLayerTable(LayerName), OpenMode.ForWrite)
acLyrTblRec.IsLocked = True ' lock layer
LayerLockDB = True
acTrans.Commit()
End Using
myDb.Dispose()
End Function
dwgfilename in this case is the name of the current dwg.
I get no erros when running/debugging this, but my layer remains unlocked.
I'm guessing it has to do with the new database object, as if the layer is locked in that database but is not updated in the current dwg.
I guess, fundementally I need to understand what this:
myDb.ReadDwgFile(dwgFileName, FileOpenMode.OpenForReadAndAllShare, False, "")
is trying to do & why it seemed like I needed it in the first place (note my original program (where I thought this worked) opens many drawings & lock a particular layer in them all)