How to change document model units

Hi,i am trying to write a import plugin with c#.But i can’t find the way to modify the document model units before read the file.Can anyone help me?

First of all, make sure you have created a File Import plug-in. Then, in the method where you read the file, you can do the following to adjust the model unit system of the document:

protected override bool ReadFile(string filename, int index, RhinoDoc doc, FileReadOptions options)
{
    doc.AdjustModelUnitSystem(UnitSystem.Millimeters, false);
    // read stuff
    return true;
}

Thank you!but i am using Rhino.Net,not Rhinocommon.Is it the same methods?

Oh, ok. Then you need to do something along the lines of

MRhinoDoc doc; // defined elsewhere
On3dmUnitsAndTolerances unitsAndTolerances = 
    new On3dmUnitsAndTolerances(doc.Properties().ModelUnitsAndTolerances());
unitsAndTolerances.m_unit_system.m_unit_system = IOn.unit_system.millimeters;
doc.Properties().SetModelUnitsAndTolerances(unitsAndTolerances);

As you can see from the complexity of the two code snippets, I can’t encourage you enough to switch to RhinoCommon :smile:

OK,i’ll try to switch!Thanks!

I have an other question.which method can replace the “MRhinoDoc::SetTitle”?

I don’t understand the question. What are you trying to do and why?

Thanks,

– Dale

I’am trying to set the document title after reading the file.such as

And you are trying this with RhinoCommon, right?

yes!

is there any way to change whole rhino unit to meters ?
tnx ( c# , pure plugin )

For one document, use:
doc.AdjustModelUnitSystem(UnitSystem.Meters, false);

see

///

If you want to load which units get loaded into a default blank document, you need to adjust which template is loaded, using Tools > Options > Files > Template files > Default

It looks like that can be changed programmatically with https://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_ApplicationSettings_FileSettings_TemplateFile.htm

1 Like