This project has moved. For the latest updates, please go here.

line thickness

Sep 26, 2012 at 7:12 PM

First of all, compliments for this library, very useful.

I get a problem when I try setting a line thickness via the command:

line.Thickness = 0.5

In the resulting DXF no thickness is displayed. Is it a bug or I mis-used the command?

Thanks,

Giovanni

Coordinator
Sep 28, 2012 at 4:47 AM

Check the following example (also included in the source code, TestDxfDocument project), I hope it will clarify your doubts, do not confuse width, thickness and elevation, they represent different concepts that can get a little messy.

private static void LineWidth()
        {
            // the line thickness works as expected, according to the AutoCAD way of doing things
            Line thickLine = new Line(new Vector3(0,10,0),  new Vector3(10,20,0));

            // when you assign a thickness to a line, the result is like a wall, it is like a 3d face whose vertexes are defined by the
            // start and end points of the line and the thickness along the normal of the line.
            thickLine.Thickness = 5;

            // maybe what you are trying to do is create a line with a width (something that we can read it as a line with thickness), the only way to do this is to create a polyline
            // the kind of result you will get if you give a width to a 2d polyline 
            // you can only give a width to a vertex of a Polyline or a LightweigthPolyline
            // I am planning to drop support to AutoCAD 12 dxf files, so to define a bidimensional polyline the only way will be to use lightweight polyline
            // (the Polyline class and the LightWeightPolyline are basically the same).
            Polyline widthLine = new Polyline();
            PolylineVertex startVertex = new PolylineVertex(new Vector2(0, 0));
            PolylineVertex endVertex = new PolylineVertex(new Vector2(10, 10));
            widthLine.Vertexes = new List<PolylineVertex>{startVertex,endVertex};

            // the easy way to give a constant width to a polyline, but you can also give a polyline width by vertex
            // there is a mistake on my part, following the AutoCAD documentation I should have called the PolylineVertex.StartThickness and PolylineVertex.EndThickness as
            // PolylineVertex.StartWidth and PolylineVertex.EndWidth
            // SetConstantWidth is a sort cut that will asign the given value to every start width and end width of every vertex of the polyline
            widthLine.SetConstantWidth(0.5);

            DxfDocument dxf = new DxfDocument();

            // add the entities to the document (both of them to see the difference)
            dxf.AddEntity(thickLine);
            dxf.AddEntity(widthLine);

            dxf.Save("line width.dxf", DxfVersion.AutoCad2000);

        }

Sep 28, 2012 at 5:38 PM

Thank you so much, I tried this solution and it worked but I prefer keeping all the entities as lines. Is there a method to give to a layer a line thickness?

Giovanni

ps.

I'm really sorry for the private message, I was thinking the project was abandoned.

Coordinator
Sep 29, 2012 at 2:06 AM

There is an entity value (code 370), can also be applied to layers, called lineweight that can solve your problem, but this is not implemented. It is one of those values that appeared for the first time with AutoCAD2000 (if I am correct). There has been a lot of changes between AutoCAD200 and prior dxf versions that are a pain to mantain and thats why I am planning to drop support for AutoCAD 12 dxf, there must be a really, really good reason to mantain it. As an example the actual code for hatches works just fine for AutoCAD2000 dxf and up, but why it doesn't for 12 that is a pain to find out, worthless and a loss of time that can be used for something more productive. Any program out there that supports import and export dxf file should be able to handle newer versions just fine.

The best thing is that it is very easy to implement, but the drawback of this method over using a polyline width is that this value is define as 1/100 of a mm while the work units in the drawing are agnostic (one unit in a dxf can be whatever you like and one lineweight unit is always 1/100 mm). AutoCAD focus is technicall drawing and is only when you are ready to plot when you start to care about pen widths.

Daniel

Don't have to apologize for writing a private message, it is ok. The project was really abandoned, it was born because I need it but now I don't, I am only keeping it alive because there are people that seems quite interested on it. If you haven't read the discussion topic "News" there you will find a longer explanation.

Sep 29, 2012 at 12:00 PM

Thanks, I added in the code the support for the weight for lines and layers and works fine! The only thing is that AutoCAD12 format is not opened in AutoCAD after the code changing, as you predicted, even if I added something like this:

if (this.version != DxfVersion.AutoCad12)

        this.WriteCodePair(370, line.Weight);

I agree with you, AutoCAD12 dxf format has to be dropped, because other things don't work (if I remember well, also text size has a problem).

Giovanni