Can Someone Explain LayerTableRecords
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I know this is a real newbie question, but I have seen so many different ways of setting the layer table and layer table record:
Dim layTable As LayerTable = DirectCast(tr.GetObject(db.LayerTableId, OpenMode.ForRead), LayerTable)
Dim layTable As LayerTable = tr.GetObject(doc.Database.LayerTableId, OpenMode.ForRead)
myLT = myDB.LayerTableId.GetObject(DatabaseServices.OpenMode.ForWrite)
and
Dim layTabRec AsLayerTableRecord = tr.GetObject(layId, OpenMode.ForRead)
myLTR = myLT(sourceLayer).GetObject(DatabaseServices.OpenMode.ForWrite)
Can someone explain to me when to use which version? What is the layertablerecord, is it the layer ID?
I have this code (some of which is borrowed from a post on this website) and changed to locate an existing layer. When it gets to the line:
layerId = layTable.Add(layTabRec)
It crashes. I know it has to have something to do with what I'm passing it.
Public Sub FreezeNewLayerInVPs(ByVal pageNumber)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim layerToFreeze As String = "DETAIL_" & pageNumber
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim layTable As LayerTable = DirectCast(tr.GetObject(db.LayerTableId, OpenMode.ForRead), LayerTable)
Dim layerId As ObjectId
' Search the layers for the newly created layer
For Each layId As ObjectId In layTable
Dim layTabRec As LayerTableRecord = tr.GetObject(layId, OpenMode.ForRead)
' If the layer name is greater than or equal to 8 characters
If layTabRec.Name = layerToFreeze Then
' If the layer table record equals the new layer get the layer ID
layerId = layTable.Add(layTabRec)
End If
Next
' Freeze the new layer in all viewports
Dim ids As ObjectId() = New ObjectId(0) {layerId}
Dim layoutDict As DBDictionary = DirectCast(tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead), DBDictionary)
For Each entry As DBDictionaryEntry In layoutDict
If entry.Key <> "Model" Then
Dim lay As Layout = DirectCast(tr.GetObject(entry.Value, OpenMode.ForRead), Layout)
For Each vpId As ObjectId In lay.GetViewports()
Dim vp As Viewport = DirectCast(tr.GetObject(vpId, OpenMode.ForWrite), Viewport)
vp.FreezeLayersInViewport(ids.GetEnumerator())
Next
End If
Next
tr.Commit()
End Using
End SubThanks for your patience and help,
Mark