Read 3dm files in different unit system

Hi all,

I need a little help about reading 3dm files and unit system. I will try to explain with more details.

I open Rhino project with unit system in millimeters, then export one object in the 3dm file. I guess that in the 3dm model also there are information about unit system beside geometry. Then I open project in Rhino with unit system in inches and try to read 3dm file via code, made some transformations and drawn the object in the project. When I measure the object (let’s say from one end point to another) it gives me the same value in inches and millimeters (same number, for example distance is 1000 mm and 1000 inches when I open the 3dm file in Rhino project in millimeters and inches). For test, I try Import command and Import option from Rhino to load the object and the object in imported successfully and the dimensions that I measure were OK. Is there any changes that I should made via
code to import 3dm object correctly?

I also made another test: export 3dm file only with geometry included (Save only geometry) and try to import via code and then the object dimensions was correctly.

To make correct importing of the objects in the 3dm file I also try to made some changes in the code to force unit system like this:

// read 3dm file and get the object and try to change model unit settings
const ONX_Model& model = readFile.GetONXModel(); 
ONX_Model& model1 = const_cast<ONX_Model&>(model);
model1.m_settings.m_ModelUnitsAndTolerances.m_unit_system = ON::UnitSystem(ON::inches);
model1.m_settings.m_PageUnitsAndTolerances.m_unit_system = ON::UnitSystem(ON::inches);

// try to use correct model scale
ON_Xform rotationTranform, translationTransform;
const double modelScale = ON::UnitScale(ON::millimeters, ON::inches);

Can you please tell me how I should export objects in 3dm model or how to made correct conversion between unit systems via code ( I want my 3dm files to be independed from the unit system). I still work in Rhino 5 :slight_smile:

Thanks a lot,

Best regards,


The Import command in Rhino does read the file units in the imported file and automatically scales the objects to the new unit system if it is different from the existing file’s.

Reading via ‘code’ probably does not do this - i.e. the file will be read in as unitless and thus the numbers will be come the dimensions in the importing file’s units.

The File3dmSettings class gives you access to the units, I guess you will have to read that on the file you’re importing, and then do your own conversion.

I guess that this not work correctly…

Because I work in Rhino 5 C++ I have ON_3dmSettings class but I see that this not read archive of the 3dm file correctly. See my code below:

ON_BinaryFile archive(ON::read3dm, archive_fp);
ON_3dmSettings dmSettings;
bool read3dmSettings = dmSettings.Read(archive); // return false 
////bool settRead = archive.Read3dmSettings(dmSettings); // check read from the archieve but it returns false alsoo 
ON_3dmSettings read3dmSett = const_cast<ON_3dmSettings&>(dmSettings);
read3dmSett.m_ModelUnitsAndTolerances.m_unit_system = ON_UnitSystem(ON::inches); // try to changes units 
read3dmSett.m_PageUnitsAndTolerances.m_unit_system = ON_UnitSystem(ON::inches);
////archive.Write3dmSettings(dmSettings); // test : try to write but it returns false also 

ON_wString error_log_string;
ON_TextLog error_log(error_log_string);
bool result = model.Read(archive, &error_log); // after read from the settings model could not be read there is errors in the archieve

I export all 3dm files with Save only geometry and it works correctly in the Rhino (but I’m still not so sure about object scaling). Any idea about how to made unit system conversion via code.

Thanks a lot,


No idea how to code in C++… sorry.

Should this thread be in the Developer category?

1 Like

tnx I forgot to change the category :smiley:

Hi @Ivi,

Just curious, why are you reading a 3dm file from your plug-in and not just scripting the Imort command? There is a lot of work that Rhino does when importing a model with a different unit system than the current model. Perhaps you should just take advantage of that.

– Dale