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

Problem of load dxf

Feb 26, 2015 at 8:10 AM
Hello,
When I load dxf file, the dimension:
if (dxf.Dimensions[i] is LinearDimension)
 {
         LinearDimension aligned1 = (LinearDimension)dxf.Dimensions[i];
          Line line = (Line)aligned1.Block.Entities[0];
//From entities 0 to 2 is correct.
//But from entities 3,4 (of narrow) is not updated
}
Thanks
Coordinator
Feb 26, 2015 at 2:11 PM
I will also answer here your other question in your previous topic "About dimension position when load file.dxf " since both are related.

In a dxf file the dimensions, that it might contain, store the entities that make their actual drawing as a block, something that it seems you already found by yourself. All that information is enough to draw the dimension, but not all entities contained in the block have to be lines. This line is wrong:
Line line = (Line)aligned1.Block.Entities[0];
You have to safely cast the EntityObject returned by "aligned1.Block.Entities[0]" to its actual type. Line is one of the several classes that inherits from EntityObject, and the dimension block might contain lines, points, texts, multiline texts, solids, inserts, and/or circle arcs; I think those are all but do not quote me on that. In your case it seems that indexes 0 to 2 are lines, and 3, 4 are not, I really do not understand what you mean by "But from entities 3,4 (of narrow) is not updated". You cannot even rely that they will always appear in that order.

This is the same problem you were having before on how to get the dimension references, casting is a basic OOP procedure. If you work with Visual Studio and want to see the full picture of the inheritance relationships between the classes of the library, you can view the Class Diagram.

The method "public static Block Build(LinearDimension dim, string name)" you were talking about should not to be used, that is why it belongs to an internal class (internal use only). It is used when the Dimension entities are added to the document.

All predefined arrow types are described in the DimensionArrowhead class. They are used by the dimension style variables DIMBLK, DIMBLK2, and DIMBLK2. See the netDxf and AutoCad documentation for more information.

As a side note, if you are creating a dimension instead of reading one from a file, initially the dimension Block property will contain null until it is added to the document, it is at that moment when the entities that make its picture are created. As a rule of thumb, once an entity is added to the document it should not be modified, the change in some properties will not make any harm but in others it will.

Daniel
Feb 26, 2015 at 2:47 PM
Edited Feb 26, 2015 at 2:58 PM
Hello,
Thank for your answer. Now I can understand more project with your help.
I work for the dimension such like this:
link
This is _OPEN dimension, it is linear dimension.
  1. By using the following code, I can find the CodeName of Entities of this dimension:
if (dxf.Dimensions[i] is LinearDimension)
                {
                    LinearDimension aligned1 = (LinearDimension)dxf.Dimensions[i];
                 
                    for (int j = 0; j < aligned1.Block.Entities.Count; j++)
                    {
                        sendtexttorichTextBox1(aligned1.Block.Entities[j].CodeName);
                    }
                }
Then I got:
LINE --->dimLine
LINE--->ext1Line
LINE--->ext2Line
INSERT--->arrow 1
INSERT---->arrow 2
MTEXT----->text
POINT
POINT
POINT
I just test for this example. For another or general case, I know I should use the method as you teach me.
  1. Next, I use the following code to get dimline, ext1line, ext2line
dimLine = (Line)dim.Block.Entities[0];--->result: StartPoint(0,100,0); EndPoint(0,5508,0)--->correct
ext1Line = (Line)dim.Block.Entities[1];--->result: StartPoint(10883,100,0); EndPoint(10883,5508,0)--->correct
ext2Line = (Line)dim.Block.Entities[2];--->result: StartPoint(__350__,5408,0); EndPoint(10533,5408,0)--->correct
(350) value above is arrow size
  1. Next, I use the following code to get arrow1, arrow2
           Insert arrow1 = (Insert)dim.Block.Entities[3];
            for (int i = 0; i < arrow1.Block.Entities.Count; i++)
            {
                Line l1 = (Line)arrow1.Block.Entities[i];
                MessageBox.Show(l1.StartPoint.ToString() + "\t\t" + l1.EndPoint.ToString());
            }
-->result is three lines of first arrow:
Line 1: StartPoint(-1,0.166,0); Endpoint(0,0,0);
Line 2: StartPoint(-1,-0.166,0); Endpoint(0,0,0);
Line 3: StartPoint(0,0,0); Endpoint(-1,0,0);
These values of Line 1,2,3 are initial values that are defined in DimensionArrowhead class.
So I told you it is not updated such like that.
It should be appropriate with (350) values above.
Thanks for your project.
Coordinator
Feb 27, 2015 at 6:49 PM
In your case the dimension arrows are represented by an Insert entity. Basically, a block contains its name, geometry, and base point; an Insert entity is actually a reference to a block definition that specify the location, scale, and rotation. Therefore, you still need to transform the entities defined in the block by the scale, rotation, and position defined in the Insert object.

And remember not all arrowhead blocks are made of lines, they might also contain circles, solids, arcs, and/or lightweight polylines.

Daniel