Units in a SketchUp model and faces with short edges

Hi,

I was doing some work on the Rhino to SketchUp export plugin recently and I noticed a TODO I had made about setting the units in the SketchUp file if Rhino’s units were one of the SUModelUnits enums (setting a scale factor based on our units to inches otherwise). I see a SUModelGetUnits function in the SDK but no SUModelSetUnits, so unless the Rhino model was in inches I’m always scaling. How do you set the unit system on a SUModelRef? Just for grins I tried changing the unit system in SketchUp 2016 too but couldn’t figure that out either. Are you guys just inches now and SUModelGetUnits is for legacy files?

The reason I even started looking at the unit system again is I noticed that edges smaller than about .002 inches don’t get turned into faces right when I bring a model exported from Rhino into SketchUp. It’s fine to have a component with a scale transform that makes it smaller but not if the geometry itself has edges shorter than that. Is that supposed to happen? Is there a certain length, under which stuff doesn’t work right? I was going to pop up a message box to warn users when they have geometry that might not open right in SketchUp but I wanted to make sure I got it right.

Tim

Forgot to mention. Looks like the version of the SDK we’re using (based on the .dll version info) is 16.0.19912.0.

I’d like to resurrect this thread. Can we please have a simple means of setting the unit system on the model in C API? The analog of SUModelGetUnits but for setting (ie. SUModelSetUnits). Is this hard to do? If there is no other way than using the options manager stuff, can you please give us a clear example in C, or point us to one if one already exists. I just downloaded SDK_WIN_x64_2021-0-339 and I can’t find anything in the samples.

Thanks.

Tim

Wasted time ...

ALL SketchUp (and .skp file) internal coordinates are in inches. The units settings affect only display of coordinates, lengths, areas and volumes in the GUI, and some of the formatted string output methods of the APIs.

Yes, This is the small face scenario. SketchUp was designed to model buildings and so has an internal tolerance of 0.001". (So coordinates closer than this will get merged.)

There is the “Dave method” in which a component is drawn at a larger scale, and then an instance is placed in the model scaled down to actual size. This is usually done manually, but could also be done programmatically.

There are countless forum posts about this in the main SketchUp modeling categories.

More wasted time ...

I think that this was an early convenience “shortcut” function (perhaps used by the online 3D Warehouse to quickly get the user units of a model for online display.)

There is an issue in that it uses a “forgotten” enum that was not updated when yards was added as a new user unit.

I do believe that querying the options manager should be safer as it uses it’s own enum for the units.

I filed an API Issue on this a year ago

enum SUModelUnits lacks a member for the new yards unit · Issue #442 · SketchUp/api-issue-tracker · GitHub

… in which @tt_su said …

I’m leaning towards deprecating SUModelUnits and SUModelGetUnits as it appear to be redundant. Don’t want to bloat SUModel* further by adding functions for area and volume units. SUModelGetUnits is even asymmetrical, no setter.

If you have thoughts @tim, please add them to the open issue, and / or file a specific request in the GitHub API tracker for the model level setter method(s). But, I can say right now that it is unlikely to happen as there are multiple options that must be set in the correct combination in order to set the user units. (Basically the settings must match a valid setting in the GUI.) The Units Options manager can do this.

Example: When LengthFormat is Engineering, the LengthUnit must be Feet.

See also …

What's the right way to set unit of model with C API? - #4 by DanRathbun

Hi Dan,

I don’t care about the edge stuff. I handled that a long time ago. Not long after I got crickets from my initial post.

Here’s what I can tell you is fact because I can demonstrate it. If you make a model in SketchUp with the units set to meters, for example, and make a box that is 3x4x5m. Save that model as a .skp file. You can open that file in Rhino and confirm that the units were set to meters and the box is 3x4x5m. I know that it is using the unit system from SUModelGetUnits because I wrote the Rhino plugin that opens SketchUp files.

What I currently do on export is scale the model from whatever unit system Rhino is using to inches because there is no way to set the model’s unit system, with the SDK, that I understand. I’d like the user to be able to make a model in Rhino using a unit system that SketchUp supposedly supports:

@enum SUModelUnits
@brief Units options settings
*/
enum SUModelUnits {
SUModelUnits_Inches,
SUModelUnits_Feet,
SUModelUnits_Millimeters,
SUModelUnits_Centimeters,
SUModelUnits_Meters
};

so that a user can roundtrip a SketchUp file and preserve the units instead of having them converted to inches.

Tim

I never saw the original post. And I am bowing out of this topic now. All I will say regarding this …

… is that again, everything internally in SketchUp, LayOut and their file formats is in inches.

I humbly apologize. I just looked at the import code. While I do get the unit system from the file using SUModelGetUnits, I am scaling the geometry with a unit scale from inches to whatever the unit system SUModelGetUnits returns. So you are right, inches internally regardless of the unit system.

I guess I’ll let this rest. However, if the SkectchUp API devs ever do any unit system updates can you please let me know. I guess I’ll get notified via email if you reply to this forum post.

Tim

That would be a major change. It would certainly be messaged if that ever happened.

:pinched_fingers:

In all seriousness though, if one can save a SketchUp file in Meters from SketchUp (even if it a display thing and not internal). Why can’t you code it so that said display user option is set to meters within an exporter?

Only a human can get into Model Info>Units and change it to Meters with a mouse click? Like no other pc quantum pc in 2023 can access that variable and set the value to Meters through code?

You can. Several built in exporter already have this option.

No.

You do not need a quantum pc (SketchUp doesn’t run on it anyway…). You just need to learn how to write proper code to set.

1 Like

I’m not sure what your bottom line is.

Are you wondering how to accomplish units conversion in an exporter you write yourself? If so, you need to look at the UnitsOptions in the model’s options dictionary and its key,value pairs. I can’t tell you exactly where to find those in the SDK as I don’t use it, I get them from the SketchUp Ruby API. If you are convinced they have been omitted there (which seems unlikely), you could submit a request to add them.

Are you wondering why they aren’t present in some of the exporters? I note that there are options to set units in the options in several of the existing exporters but not in others. And in the ones that offer this option, the model units are the default. If you are specifically asking about one or more exporters that don’t offer the option, you could rephrase your question to be specific about them.

If you are wondering why SketchUp uses inches as its internal units regardless of the display units of the GUI, that is an entirely different matter that was discussed a couple of years ago in this topic. Regardless of the state of the world about units of measurement, this is not likely to change. The devs have stated that internal units are ultimately arbitrary and they don’t see a sufficient reason to undertake a massive rework of the code base to change them.

@dezmo I was mainly using hyperboles.
@slbaumgartner I am not a developer myself. Was talking about Rhino exporter which @tim seems to have developed.

If this is the case I take it all back.

@tim Would this be possible to do for Rhino exporter? It would be greatly appreciated. I read your comment on the youtrack entry for keeping units in Rhino exporter in which you said it was “unlikely to change” but these guys here telling it should be possible? Thank you.

I’m not sure they’re talking about exporters in other apps that use the SDK to go to SU. I think they’re talking about exporters in SU to go to other formats. If I’m confused, someone please chime in.

1 Like

I was indeed thinking about an exporter from rather than into SketchUp, but I see no reason an importer in SketchUp or exporter for another app couldn’t use the SketchUp SDK. It’s just a standalone library that can write a SketchUp model. Since the skp file format is proprietary, how else could you (legally) write one?

1 Like

I did write an exporter (and an importer) to export and import SU files into Rhino. You can get what the units were set to in the SU file on import with the SDK function SUModelGetUnits. You still have to scale the geometry from inches to whatever but no big deal. There is no SUModelSetUnits though and maybe it’s possible to set them some other way but I am too dumb to figure it out.

What about

https://extensions.sketchup.com/developers/sketchup_c_api/sketchup/struct_s_u_options_provider_ref.html

Edit: I downloaded the SDK and spent a few minutes looking for the equivalents to what I know works in the Ruby API. Here’s the equivalent process:

  • Get a SUModelRef from, for example, SUModelCreate
  • Get the model’s SUOptionsManagerRef via SUModelGetOptionsManager
  • Get the units SUOptionsProviderRef via SUGetOptionsProviderByName
  • Set the desired units values via SUOptionsProviderSetValue
1 Like

Thanks. I’ll give that a try tomorrow.

This is working for me. Thanks for the tip. I would not have known to go in that direction.

Tim

2 Likes