Forcing DXF Export to use INSUNITS

Hiya,

I’m running in to a problem where some exported DXF is missing INSUNITS, even documents started from a new template in mm. The software I’m using respects INSUNITS, and like AutoCAD, defaults to inches if INSUNITS is not set. This means my 1200mm x 500mm document is now 1200in x 500in and my digifab software is not a happy camper.

Right now I’m manually editing the .dxf files to set INSUNITS but am wondering how I can do this from within Rhino, as I often convert inch units to mm units when importing a third-party dxf file.

thx

Preferences>Units. Set units to mm. Answer NO to the question “Do you want to scale the model?”. Done…

–Mitch

That’s not repeatable here (on Windows).

Just so I get this right…
My standard template is a mm document. I create some curves, export to DXF using the default scheme and then open the file in notepad. The INSUNITS read:

$INSUNITS
70
4
9
According to [this page][1] that means millimeters. You are saying that starting with a mm template and exporting to DXF sets this to 0? Does it make a difference if you use another scheme?

OK - reading a bit more…

Apparently the INSUNITS is only for AutoCAD DesignCenter blocks.

It is the MEASUREMENTvariable that sets drawing units and should be 0 = English or 1 = Metric.
In my test DXF this is set to 0 whereas it should be 1, or? @tim?

Hi,
Can you explain what you mean by “missing INSUNITS”?
What is the value of INSUNITS in a dxf file when Rhino model units are mm when you save?
When you manually edit the dxf file to set INSUNITS, how do you do that, and what value do you set it to?

When I export a model with mm units from Rhino to dxf, INSUNITS is 4 in the dxf, which, as Wim said, means mm. Do you see something different?

Thanks,
Lowell

[edit: collecting my responses]

My reference is this document – http://www.autodesk.com/techpubs/autocad/acad2000/dxf/ – several of the packages I’m working with read/write INSUNITS to set the unit for the entire document and Rhino also sets the INSUNITS header variable on many of its exports.

The problem is that I’m not seeing it consistently in documents I export. It works correctly enough that I don’t check every DXF export, but from time to time when I load the file in my laser cutter it barfs saying it can’t print something 1280 inches by 500 inches. That file is missing INSUNITS, I edit it in, and can cut just fine.

This is OS X, so Settings->Units and it’s set to mm automatically when I open a new document using the mm template. If I open a new mm template document, make some changes, export the DXF, it usually has INSUNITS set to 4. (note: I’m not certain what happens if I just do cmd-N, maybe some times I get an inches document? I’ll keep an eye on that.)

I have another document (set to mm) that when I export DXF some times has INSUNITS set and other times not. I’ll attach that document, it’s just a test sheet.
L-rotate-180.3dm (80.0 KB)

I started by checking the MEASUREMENT variable, but it was set to 0 (inches) on documents that have Settings->Units set to “mm”.

INSUNITS of 4 is what I’m expecting for mm documents, but my DXF reader can handle other units as well or throws a valid error message about things like “Light Years”.

Are you consistently using the same export scheme?

In a quick test with your L-rotate file, using the Default scheme sets the $INSUNITS parameter to 4 and is correct.

But when I use the CAM Imperial scheme, there is no $INSUNITS parameter. There is a INSUNITS entry and its Group code is not 70 but 350; its value is 13F. The Autodesk page doesn’t say anything about any of this. Google returns actual DXF files with INSUNITS 350 (so it appears to be used elsewhere) but no reference. I’m sure @lowell has this under control.

But anyway, the only way of getting anywhere with this is if you find out what is different from time to time - and perhaps the scheme has something to do with it?

And all this time I have thought DWG and DXF were unitless…

Here is the content from: http://www.autodesk.com/techpubs/autocad/acad2000/dxf/header_section_group_codes_dxf_02.htm

$INSUNITS

70

Default drawing units for AutoCAD DesignCenter blocks:
0 = Unitless; 1 = Inches; 2 = Feet; 3 = Miles; 4 = Millimeters;
5 = Centimeters; 6 = Meters; 7 = Kilometers; 8 = Microinches;
9 = Mils; 10 = Yards; 11 = Angstroms; 12 = Nanometers;
13 = Microns; 14 = Decimeters; 15 = Decameters;
16 = Hectometers; 17 = Gigameters; 18 = Astronomical units;
19 = Light years; 20 = Parsecs

As far as I know, when you’re inside ACAD, it doesn’t necessarily know what units you are in - note from the images below, for drawing units, you have “imperial” (inches) and “metric”… It’s only once you go into “paper space” that you tell it what your unit represents and what scale you want it printed at… The INSUNITS is for dealing with automatic scaling of inserting blocks, etc. - a sort of indirect way of telling you what unit your main file is in, I suppose.

It seems plausible that others trying to deal with the unitless concept in acad files might use INSUNITS since it is a persistent value representing unit scaling even if AutoCAD doesn’t use it exactly that way.

That’s a good clue. I’ll seed if I can track down why that happens.

I did a bunch of test exports with Rhino units set to inch and mm, and haven’t seen anything but inch or mm in the insunits field in the dxf’s.

I traced through our code. The part that deals with this is pretty simple.
If the Rhino model units are inches, feet, miles, millimeters, meters or kilometers, INSUNITS gets set to the corresponding value. Otherwise, for any other setting of Rhino units, the default is mm. I tried NoUnits, Custom and LightYears and the default handling worked correctly and wrote 4 for mm.

I’d be happy to chase down any other clues, but at this point, I’m baffled how you can get the wrong type code or value in that field.

Lowell

Centimeters should probably in there too… hopefully.

OK, I’ll fix that

OK, thanks Lowell. Probably the most used unit by architects on this side of the pond… --Mitch

I’m working with a variety of third-party tools that at least read INSUNITS if it exists, but I’m not sure if that’s following a standard or just being helpful.

I do appreciate that Rhino can export INSUNITS, I’d just like to see it in every DXF export. I’m trying to follow that rule as well and always set INSUNITS when my software writes DXF, but if there is a better, more AutoCAD way, I’ll follow their example.

I should have started out by saying that I have to switch between metric projects (friends in the EU or Japan) and inch projects (stateside) and it’s really, really convenient when any format has a “units=” feature. Rhino is almost there (at least in DXF) and it makes my job so much easier when I can just load a file and have Unit Magic happen.

I don’t know of a better way.
I still haven’t seen a case where Rhino doesn’t set INSUNITS to the value corresponding to Model space units.
If you or anyone can come up with a way do duplicate that, I’d sure be happy to work on fixing it.
Or if you have any other suggestions about what would make it work better, let us know about that too.

gah. the email notification of your post went in to my spam box, sorry.

I will try and replicate this and I can post the .3dm file and instructions. Is there a way I can turn on some sort of debug logging in Rhino 5 OS X while I’m replicating this problem?