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

dxf coordinates conversion

May 19, 2013 at 12:29 PM
Hi Daniel,
Can you explain how to use your library to do the following task:
  • Read dxf file
  • Convert coordinates for all entities of the dxf file to another projected coordinates system (reproject)
  • Update the dxf file (or write to a new dxf file)
    Thanks and Regards,
    Nguoi NV,
May 19, 2013 at 7:35 PM
You can find in the TestDxfDocument a lot of samples on how to load and save dxf documents. The transformation from one coordinate system to another you will have to do it yourself. First you will need to build the transformation matrix between coordinate systems and multiply it by the data of the entity you wish to transform.

Please try to be more specific and build an example of what are you trying to achieve to get a more specific answer.

May 20, 2013 at 4:00 AM
Edited May 21, 2013 at 10:30 AM
Hi Daniel,
Thank you for your reply.
I have another question. I want to change position of all texts. The code as follows:
       DxfDocument dxf = DxfDocument.Load(My_Dxf_FileName);
       var texts = dxf.Texts;                   
        for (int i = 0; i < texts.Count; i++)
            var vector3 = new Vector3(new_X, new_Y, new_Z);
            texts[i].Position = vector3;                 
        //now i want to update the dxf file: My_Dxf_FileName / or save to new dxf file. Here i did (save to new dxf file):
Can you please let me know if the code is correct.
Thank you in advance,
May 21, 2013 at 7:23 PM
Edited May 23, 2013 at 3:01 AM
The code you are showing it's correct. In general, I won't recommend to edit the entity properties once they are added to the dxf document. There are entity properties that can cause errors if they are not treated with a little bit of care, this is specially true with the properties that references table objects like layer, linetype, textstyle,... it can be done but you have to make sure that the table lists are edited accordingly. The worst scenario is to edit the dimension properties because is during the process of adding them to the document when the block that represent the dimension drawing is generated.

The safest way is to first remove the entity that you want to modify from the document and then add it again, like for example:
DxfDocument dxf = DxfDocument.Load("text.dxf");
// since we will be modifying the original dxf.Texts list with RemoveEntity and AddEntity methods, we need to make a copy of it
Text[] texts = new Text[dxf.Texts.Count];
dxf.Texts.CopyTo(texts, 0);
// iterate through our copy list
for (int i = 0; i < texts.Length; i++)
    // get the text we will modify
    Text text = texts[i];
    // remove it from the document
    // edit your text
    text.Position = new Vector3(i, i, 0);
    // add it again to the document
// save your modified file, you can also if needed overwrite the original without problems
dxf.Save("text modified.dxf");
But a I said it is safe to edit the text position without side effects.

May 22, 2013 at 4:34 AM
Edited May 22, 2013 at 5:35 AM
Hi Daniel,
Thank you very much for your help.

May 25, 2013 at 9:07 AM
Edited May 25, 2013 at 9:13 AM
Hi Daniel,
I need your help again.

I want to count the number of Entities in the dxf file using the following codes:
These codes give the correct result.

For Polylines, i use the same code:
But this code always gives Zero.
Please help me to fix it.
Thank you very much,
May 26, 2013 at 10:31 AM
Perhaps the polylines that you are looking for are in the LwPolylines list. Remember, there are two kinds of polylines: the generic 3d polyline (Polyline) found in the Polyline list, and the polyline 2d (LwPolyline) located in the LwPolyline list.

May 26, 2013 at 11:47 AM
Edited May 27, 2013 at 6:36 AM
Hi Daniel,
Could you please tell me how to get/set Spline Entities?
I cannot find a property like dxf.Splines.

Thank you,
May 28, 2013 at 1:28 PM
My fault. Update your code I just added the missing Splines property to access the splines list of the DxfDocument, the Dimensions property was also missing.

May 28, 2013 at 2:45 PM
Thank you very much Daniel for your amazing library.
I update now.

Jun 1, 2013 at 4:51 PM
Hi Daniel,
I need your help again.
Please tell me how to get / set Helix entity.

Thank you,
Jun 1, 2013 at 6:50 PM
The Helix entity is not implemented. You can find the full list of available entities at the main project page.

Jun 2, 2013 at 7:46 AM
OK. Thank you Daniel,