Author Topic: How to get the numeric LineWeight value of one Polyline?  (Read 2460 times)

0 Members and 1 Guest are viewing this topic.

waterharbin

  • Guest
How to get the numeric LineWeight value of one Polyline?
« on: April 13, 2015, 11:07:13 PM »
Hello,everyone.
I ues the LineWeight property to get a Polyline's line weight. Like this line of code:
Code: [Select]
myPolyline.LineWeight.ToString()But sometimes I get a "ByLayer", not he numeric value. How should I fix it?
I suppose other objects would have the same problem. Since I would like to get a line's LineWeight value later, I would very much like to know how to deal with this problem.

n.yuan

  • Bull Frog
  • Posts: 348
Re: How to get the numeric LineWeight value of one Polyline?
« Reply #1 on: April 14, 2015, 09:31:34 AM »
LineWeight is of type "enum", which can be int, short, long, byte... but by default, it is of type "int" (or Int32) and is it the case for LineWeight.

So, you directly cast int and LineWeight to each other:

int lw=(int)myEntity.LineWeight;

Or

int lw=0;
myEntity.LineWeight=(LineWeight)lw; //This is the same as: myEntity.LineWeight=LineWeight.LineWeight000;

waterharbin

  • Guest
Re: How to get the numeric LineWeight value of one Polyline?
« Reply #2 on: April 14, 2015, 10:21:26 PM »
Hi, yuan.
I have already try your solution. But when it is "ByLayer", the cast result is "-1". And so, when I cast "-1" back, it is "ByLayer". Still can not get the numeric value.

kaefer

  • Guest
Re: How to get the numeric LineWeight value of one Polyline?
« Reply #3 on: April 15, 2015, 06:39:37 AM »
Hi, yuan.
I have already try your solution. But when it is "ByLayer", the cast result is "-1". And so, when I cast "-1" back, it is "ByLayer". Still can not get the numeric value.

That is the numeric value. May I suggest that you look at the public declaration of the enum named Autodesk.AutoCAD.DatabaseServices.LineWeight?

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: How to get the numeric LineWeight value of one Polyline?
« Reply #4 on: April 15, 2015, 10:58:21 AM »
If you want to get what the resulting lineweight is when the object's lineweight = ByLayer, you will need to get the value from the Layer's lineweight property.