01 July 2008

Starting with layers (includes finding the current layer name)

Thought I'd add a few related articles today all about layers. I'll post them in separate articles so they don't get all mixed together.

It is a very wise idea to only have one open transaction at any time so most of the functions I post from now on will accept a transaction or a database object, among other things, as arguments.

Finding the current layer's name:

  Public Function GetCurrentLayerName(ByRef oDb As Database, _

                                      ByRef oTrans As Transaction) As String

    ' Create a layer object

    Dim oLayer As DatabaseServices.LayerTableRecord


    ' Set our return value to nothing

    Dim retVal As String = Nothing



      ' Check if the layer exists...

      oLayer = CType(oTrans.GetObject(oDb.Clayer, OpenMode.ForRead), LayerTableRecord)


      ' Return the current layer name

      retVal = oLayer.Name

    Catch ex As System.Exception

      MsgBox(ex.Message, MsgBoxStyle.Information, "Error in GetCurrentLayerName")

    End Try


    Return retVal

  End Function

Passing in the active database object and a transaction object, oDb.Clayer returns the current layer's object id so we need to do a GetObject on it to return the actual layer entity. Once we have it we simply check the name property.

No comments:


All materials on this site are provided "as is" and without any warranty. Any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the authors be liable to any party for any direct, indirect, incidental, special, exemplary, or consequential damages arising in any way out of the use or misuse of this site.