GH plugin in different Model Unit System

Hello all,

I’m developing a plugin where I need to create default values in the code. These values need to be updated according to the model unit system in Rhino. For example, if the user is using meters, the default value is 1.00. If the user is using inches, the constant value needs to be updated to 39.37.

To achieve this, I created a class that takes the model units from the Rhino document and updates the constant value for the plugin accordingly.

Does this approach make sense? Because this Class is called every time a node is with default values is used.
Is there a different approach I should take to make it more efficient?

Any clues would be very helpful.

Thanks in advance,
Carlos

Hey @cidelab,

just wanted to add 2 cents, that in the past I tried to (as far as I could) not depend on Rhino document’s values / settings and place all possible settings inside the definition / plugin itself, rather than depend on document’s. It’s because it’s much more predictible for me this way if all settings are unrelated to document. Otherwise I’d have to always double check and remember to also control properly Rhino’s document / settings when I open a definition. I know many plugins actually prefer depending on document (Grasshopper itself is doing it as well :frowning: ) so looking forward to get to know these methods for doing so as well.

I think your approach is good. If you wanted the user to be able to change the unit system a little more easily, you could add a Param_ModelUnitSystem as an input to your component. You could make it optional and use the active Rhino Document unit system as the default if the user does not specify a unit system via the parameter. Otherwise, the user can manually set the input parameter via right-click menu or by using the Unit System parameter (found under Params → Primitive). This is all available in Rhino 8.

2 Likes

Interesting and scary.
Always used Grasshopper without caring about unit system. Just real numbers.

As this is “on topic”…
Can you explain what are its uses?
Which other GH component uses that “m” type params?
There are some under the new “Rhino” tab?

1 Like

There are only a few components which use the Unit System parameter… off the top of my head, I know the Model Lineweight component and the Text Field Expression component uses it. The Lineweight component uses it because it will change the scale of the lineweight depending on what units you specify. The other component only uses it if a specific expression is used. I believe there’s also a Convert Units component which will scale an object from a source unit system into a target unit system.

1 Like

Thank you Andy,
I considered that approach, but my understanding is that I need to override all methods in the component menu, bake, name, etc. Is that correct? It would be simple to add an option in the right click menu?.

The plugin is for GH 1 and Rhino 7. I haven’t think in the migration to V8 yet.

All the best.
Carlos.

I see. Well if you’re sticking with Rhino 7 then these new features are moot anyways. I’d say your initial approach is probably the correct approach.

1 Like