Creating New Layer With Description - Description Fails 'Silently'

Creating New Layer With Description - Description Fails 'Silently'

Anonymous
Not applicable
1,033 Views
3 Replies
Message 1 of 4

Creating New Layer With Description - Description Fails 'Silently'

Anonymous
Not applicable

hi - i'm stuck at trying the above:

 

a new layer is created fine, name checked and assigned, colour assigned, plot property, all fine (and as per the autocad .net developer illustration for creating layers).

 

however, the description string is not attached to the new layer; i tried

newlayer.description = "string",

newlayer.description = stringvariable, and lastly

newlayer.description.insert(0, "string").

 

no success, the description property of the newly created layer stays empty.

 

suggestions welcome, thanks

 

felix

0 Likes
Accepted solutions (1)
1,034 Views
3 Replies
Replies (3)
Message 2 of 4

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

what AutoCAD version do you use? And just to make sure ... you don't get an exception?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 4

Anonymous
Not applicable

hi alfred

 

no exceptions, no; i'm using autocad 2011 with vs2010 and the .net framework 4.

 

also, i've used the debugger to check .isnewobject (which shows true for the new layer) and the .description property (which is simply blank).

 

felix

0 Likes
Message 4 of 4

jeff
Collaborator
Collaborator
Accepted solution

Hi Felix,

 

I have noticed this with certain properties for oyher objects but usually the first thing I will try is to set the property after it has been added to the database.

 

Not sure why it is like this.

I guess you are using VB but here is a example

 

 

        <CommandMethod("CreateNewLayer")> _
        Public Sub CreateNewLayer()
            Dim layerName As String = "TestLayer"
            Dim layerDescription As String = "This is TestLayers Description"

            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor


            Using trx As Transaction = db.TransactionManager.StartTransaction

                Dim lt As LayerTable = trx.GetObject(db.LayerTableId, OpenMode.ForRead)

                If Not lt.Has(layerName) Then

                    lt.UpgradeOpen()
                    Dim ltr As LayerTableRecord = New LayerTableRecord()
                    ltr.Name = layerName
                    ltr.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 1)

                    lt.Add(ltr)
                    trx.AddNewlyCreatedDBObject(ltr, True)
                    ltr.Description = layerDescription

                End If

                trx.Commit()
            End Using
        End Sub

 

You can also find your answers @ TheSwamp