Author Topic: Which layer properties can be set for a new layer?  (Read 2570 times)

0 Members and 1 Guest are viewing this topic.

cnicho

  • Guest
Which layer properties can be set for a new layer?
« on: February 19, 2013, 06:39:14 AM »
Hi
When I try to create a new layer with a Description value set, the newly added layer's Description is not set to the value I assigned. Example code:-

Code: [Select]
LayerTableRecord ltr = new LayerTableRecord();
ltr.Name = myName;
ltr.Color = Autodesk.AutoCAD.Colors.Color.FromColor(myColour);
ltr.Description = myDescription;
ObjectId ltId = lt.Add(ltr);
tr.AddNewlyCreatedDBObject(ltr, true);

What I have to do is update it after insertion.

Is that to be expected or is my code lacking something?
Thanks
Craig
AutoCAD 2013, VS2010 SP1, C#
« Last Edit: February 19, 2013, 06:42:23 AM by cnicho »

fixo

  • Guest
Re: Which layer properties can be set for a new layer?
« Reply #1 on: February 19, 2013, 07:24:18 AM »
You've forget about linetype in this code snip
that will be loaded before of creating the layer
See here if this helps
http://www.acadnetwork.com/topic-283.0.html

cnicho

  • Guest
Re: Which layer properties can be set for a new layer?
« Reply #2 on: February 19, 2013, 07:42:51 AM »
Yes, I was going to come back to those later.
If I use the current layer's linetype and line weight for my new layer the description is still not set.

fixo

  • Guest
Re: Which layer properties can be set for a new layer?
« Reply #3 on: February 19, 2013, 08:15:53 AM »
Try add a description before adding the color,
just a thought

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Which layer properties can be set for a new layer?
« Reply #4 on: February 19, 2013, 08:30:10 AM »

Looks like one of those things


Try adding it to the database first then set its description.


Code - C#: [Select]
  1.    [CommandMethod("TestesLayer")]
  2.         public void TestesLayer()
  3.         {
  4.             using (Transaction trx = Db.TransactionManager.StartTransaction())
  5.             {
  6.                 LayerTable lt = Db.LayerTable(OpenMode.ForWrite);
  7.                 LayerTableRecord ltr = new LayerTableRecord();
  8.                 ltr.Name = "PEEEEEEEEEEEEEEE";
  9.                 lt.Add(ltr);
  10.                 trx.AddNewlyCreatedDBObject(ltr, true);
  11.                 ltr.Description = "WEEEEEEEEEEEE";
  12.                 trx.Commit();
  13.  
  14.  
  15.             }
  16.         }

cnicho

  • Guest
Re: Which layer properties can be set for a new layer?
« Reply #5 on: February 19, 2013, 09:24:59 AM »
Yes; thanks for your replies and thanks for the reminder about line types.