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

Creating New Layer With Description - Description Fails 'Silently'

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
adadnet
683 Views, 3 Replies

Creating New Layer With Description - Description Fails 'Silently'

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

3 REPLIES 3
Message 2 of 4
Alfred.NESWADBA
in reply to: adadnet

Hi,

 

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

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 4
adadnet
in reply to: Alfred.NESWADBA

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

Message 4 of 4
jeff
in reply to: adadnet

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

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