This project has moved and is read-only. For the latest updates, please go here.

Specifying units in a DXF document

May 24, 2014 at 4:15 PM
How do I specify what I want the units to be when writing to a DXF document? Seems like a simple thing but I can't find info on it anywhere.
May 27, 2014 at 4:36 PM
As a general rule, a drawing units is whatever you want it to be. But, there are a couple header variables that, I guess, is what you are asking for. They are: LUnits that sets the linear units format for creating entities, InsUnits that specifies the drawing units for automatic scaling of blocks, images, or xrefs when inserted or attached to a drawing, and AUnits that sets the units for angles.

At the moment, I had set those properties to internal and you cannot change those values. I have not finish with them and I still need to test them. You can always manually modify the source code at your own risk.

May 27, 2014 at 7:30 PM
"there are a couple header variables that, I guess, is what you are asking for. "

Not necessarily I just want to be able to draw a line that's 5 centimeters, or a circle with a 1 inch radius. Rather than everything being in just the 'units' dimension. I don't care if its a global units setting I need to change or just specify it for the individual entity. I just want to give the entity a desired size, in a desired unit system.
May 27, 2014 at 7:55 PM
You cannot do that. All entities must share the same unit system, so, for what you are suggesting, you will need to make the conversions yourself.

May 29, 2014 at 3:20 PM
Sorry I should have been clearer...

I do want all my units to be the same (in a particular document). I just don't know how to specify what the units are.

I don't mind if I have to say something like:



Entity et = new Circle(5, Units.Inches);

or something to that effect.

There is no easy way to achieve this?
May 30, 2014 at 5:58 PM
I remit you to my first post. The unit system can only be changed at the document level, but it is a work in progress. The main variables that control this are LUnits, InsUnits and AUnits, that you can find in the DxfDocument.DrawingVariables, but, at the moment, you will need to modify the source code to make them work.

Whenever I finish with them you will end up writing something like this to set up the units:
DxfDocumentdxf.DrawingVariables.LUnits = LinearUnitType.Engineering;
DxfDocumentdxf.DrawingVariables.InsUnits = DrawingUnits.Inches;
Check the AutoCad documentation for a more detailed information on how AutoCad handles the units.

May 30, 2014 at 6:05 PM
Edited May 30, 2014 at 8:58 PM
i think the units is maybe one of the bad things of the dxf format itself. Even in big industry programs like Sketchup you can notice some really stupid behaviour. You have a model, you export dxf, then you import that dxf and it has other different size. I mean, probably the specification have a way to do that, but is so dark that even Google programers wasn`t successful on that. I wonder, if we have the most simple dxf document. One with only lines, or one with only lines and faces. Is there a way in which we can save/read the unit being used ? thanks so much Daniel for your hardwork. Sebastian Rivas
May 30, 2014 at 8:33 PM
First everybody should start to throw away the imperial system and use always the international unit system. Any none decimal system is a pain in the ass to use, to say the least. Personally, always, always, did I say always, use unitless for everything document and blocks. If I have to scale something I will do it myself.

Changing the document units seems a trivial thing to do, but if you start to take into account that blocks can also have their one system, that they can be nested, that the code 70 of the block record does not work, ... things start to get messy.


Please edit your post and delete the image banner.

And this goes to everybody I will not tolerate and will erase any kind of post with any image, links or text related with commercial stuff.
May 30, 2014 at 8:57 PM
Ok done and sorry for the info. (if is useful to mentionate, all my stuff is freeware, but the point is made :)

And yes, my way to go around this is to have a easy to use measure/scale tool.

May 30, 2014 at 9:25 PM
Edited May 30, 2014 at 9:36 PM
In the MathHelper class you can find a couple of methods: ConvertUnit and ConversionFactor if that is what you mean. Bear in mind that all this is not very well tested and it might contain errors, as an example the conversion factor from any unit to unitless should return 1.


Sorry for that but I hate to see how internet has become a big commercial, and what that company sells is not free. Even all those so called social nets are no more than a place to get costumers.