C# get lineweight from xml (so by a variable)

C# get lineweight from xml (so by a variable)

stefanveurink68AXD
Advocate Advocate
636 Views
2 Replies
Message 1 of 3

C# get lineweight from xml (so by a variable)

stefanveurink68AXD
Advocate
Advocate

So, I want to create layers, who's info is stored in an XML file. 

 

By the XML file I can get the color and linetype and apply them to the layer.  for your info: 


***

newLayer.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, Convert.ToInt16(getlaagkleur(laagnaam)));


newLayer.LinetypeObjectId = aclintbl[getlaaglinetype(laagnaam)];

***

 

However, for the lineweight I have to do it different. Question is how? Cause I can't input a variable with

 

***
newLayer.LineWeight = LineWeight.LineWeight005;

***

 

there's only some standard values I can pick. U not gonna tell me this ain't possible right????

0 Likes
Accepted solutions (1)
637 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

"... Cause I can't input a variable with..."? Of course you can, as long as the value you supply is LineWeight enum type. You did no say what data type in the XML for lineweight is. But let's assume it is an integer. SO, you can simply cast it into LineWeight enum type:

 

int xmlLw = 5; // assume the value read from XML is 5!)

newLayer.LineWeight = (LineWeight)xmlLw;  //integer 5 is cast as LineWeight.LineWeight005

 

If the xml is anything other than integer, then it would be up to you to translate that odd value to whatever LineWeight value appropreately. For example:

 

object xmlLw = [read from XML];

newLayer.LineWeight = ConvertToLineWeight(xmlLw);

 

private LineWeight ConvertToLineWeight(object xmlLw)

{

    var lw = LineWeight.ByLineWeightDefault;

    try

    {

        lw = [Do whatever conversion as needed]

    }

    catch{}

    return lw;

}

 

HTH

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3

stefanveurink68AXD
Advocate
Advocate

Works perfect! Thanks!

0 Likes