Facing issues with converting the units of Rhino objects?

Hello,

Currently, I am having trouble when converting an object’s unit to a fixed value (“centimeters”) and then change its scale accordingly, i.e if it is in mm, its scale should be increased to match the cm value, and so on.

I thought I had found a solution, when I wrote this piece of code :

const CRhinoDocProperties& doc_props = context.m_doc.Properties();
ON_UnitSystem cm_unit_system = ON_UnitSystem::Centimeters;
bool scaleAfterChangingUnitSystem = true;

ON_3dmUnitsAndTolerances& units = ON_3dmUnitsAndTolerances::ON_3dmUnitsAndTolerances();
units.m_unit_system = ON::LengthUnitSystem::Centimeters;

context.m_doc.Properties().SetModelUnitsAndTolerances(units, scaleAfterChangingUnitSystem);

But, I was wrong as this did not give me the desired result as I had hoped for. The document’s units were changed, I could see cm in the bottom of Rhino, but the actual object was left unaffected.

How would I do so?

(I am using C++ API and Rhino 6)

Hi @binigya,

This test command changes the unit system of the document to centimeters and scales all objects in the document accordingly. You can use the Distance and other commands to verify the change.


CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
  ON_3dmUnitsAndTolerances units = context.m_doc.Properties().ModelUnitsAndTolerances();
  units.m_unit_system = ON_UnitSystem::Centimeters;
  context.m_doc.Properties().SetModelUnitsAndTolerances(units, true);
  context.m_doc.Redraw();
  return CRhinoCommand::success;
}

Hi @dale !

So, doing this will also change the units of the model and its scale accordingly right ? I was doing the similar thing as mentioned in my code, was there anything wrong with my process? But, I will try again as you said and then verify with the help of the Distance command, thanks!

But also, @dale, I was going to do the following before getting your reply:

  1. Get the current document units and then get the scale factor of it between centimeters :

ON::LengthUnitSystem currentUnitSystem = (Get this through the document attributes)
double scaleFactor = ON::UnitScale( ON::LengthUnitSystem::Meters, ON::LengthUnitSystem::Centimeters )

  1. Then scale each individual object by the scale factor through the object iterator :

     //Inside object iterator loop:
    

currentRhinoObject.Geometry().Scale(scaleFactor);

So, would this approach have been applicable for this task? I will of course be testing both these methods, but I would like to know your thoughts regarding this.

Correct.

It’s hard for me to approve of the approach when I don’t know what problem you are trying to solve. I get you want to scale the model, but why?

– Dale