.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Layer description not showing in layermanager

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
R.Gerritsen4967
451 Views, 2 Replies

Layer description not showing in layermanager

Hi all,

 

I have the following (simplified) code to create a layer:

 

    <Autodesk.AutoCAD.Runtime.CommandMethod("blabla", CommandFlags.Modal)> Public Sub blabla()

        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database

        Using tr As Transaction = db.TransactionManager.StartTransaction()
            'Dim lt As LayerTable = trx.GetObject(db.LayerTableId, OpenMode.ForRead)
            Dim lt As LayerTable = DirectCast(tr.GetObject(db.LayerTableId, OpenMode.ForRead), LayerTable)
            Dim layerName As String = "hello"
            Dim ltr As New LayerTableRecord()

            ltr.Name = layerName
            ltr.Description = "bye"
            lt.UpgradeOpen()
            lt.Add(ltr)
            tr.AddNewlyCreatedDBObject(ltr, True)
            tr.Commit()
        End Using

    End Sub

The layer is created, but the layerdescription is not.

This piece of code has always worked in AutoCAD 2016 and the versions before, but now it looks like it is not working anymore on AutoCAD 2017 and 2018.

 

Is it something I'm doing wrong? Or has something changed in the latest AutoCAD releases?

2 REPLIES 2
Message 2 of 3

Add your layer first to the transaction and then add the description before committing the transaction.

    <Autodesk.AutoCAD.Runtime.CommandMethod("blabla", CommandFlags.Modal)> Public Sub blabla()

        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database

        Using tr As Transaction = db.TransactionManager.StartTransaction()
            'Dim lt As LayerTable = trx.GetObject(db.LayerTableId, OpenMode.ForRead)
            Dim lt As LayerTable = DirectCast(tr.GetObject(db.LayerTableId, OpenMode.ForRead), LayerTable)
            Dim layerName As String = "hello"
            Dim ltr As New LayerTableRecord()

            ltr.Name = layerName
            lt.UpgradeOpen()
            lt.Add(ltr)
            tr.AddNewlyCreatedDBObject(ltr, True)
            ltr.Description = "bye"
            tr.Commit()
        End Using

    End Sub
Message 3 of 3

@Keith.Brown,

 

Thanks!  I have changed it in my functions, and it works great.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost