Forcing DXF Export to use INSUNITS

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?

No help with logging I’m afraid, but let me know if you come up with something you’d like me to look at

Thanks for keeping this open. I’ve created another, simple, file that exports without INSUNITS. I exited Rhino and reloaded with the saved file and could replicate the behavior.

I created this on
rhino: 5.1 (5B161)
osx: 10.11.2 (15C50)

I’ve attached a .zip file with the 3dm, DXF, and “fixed” DXF. I fixed it by editing the DXF and adding these lines following the INSBASE entry

$INSUNITS
70
4
9

Looking at another DXF exporter I use, I find that there are two other items included between INSBASE and EXTMIN but I don’t if they’re useful or just decoration:

$MEASUREMENT
70
1
9
$UNITMODE
70
0
9
$INSUNITS
70
4
9

bug-report-20160101.zip (6.1 MB)

@jet - Thanks for the example.
I see that you exported to a Release 14 version of the dxf file.
INSUNITS was introduced in AutoCAD in Release 2000, I believe, in conjunction with DesignCenter.
INSUNITS isn’t written to versions before ACAD 2000, but it is written to ACAD 2000 files and later.

Glad it’s that simple, thanks. I’ll change my custom dxf export configs.