Changing units with one click

Here’s the issue:

Like most of the world, I work in metric and usually in mm. However, there are times when it is much better to be working in metres. It’s not difficult to change the units in Model Info and back again but it would be handy to have a shortcut that toggled between the two.

On a Mac, you have the option of Services under the Sketchup menu. I believe this enables you to write a small macro that could have a function key as the instigator. This could presumably invoke the Model Info dialog box and change the units. You would also have to change the precision because you don’t generally want precision of greater than 1mm when working in mm but you do generally want at least two decimal places when working in metres. Ideally, hitting the designated function key would swop you back but at worst case you would have to have two separate routines with different function keys. That would also enable you to build in the closing of the Model Info dialog box if you wanted.

Why do I need such a thing? Well, if I want to know the volume of foundation concrete (say), I find it hard reading 9 or 10 digits without any separators and trying to work out where the decimal point should be for reading in metres.

Of course, all this could also be achieved by SU having the alternative metre reading in the Entity Info box, but until then…

Does anyone know how to write the necessary macro? Or even know if it is possible?

It’s doable.
There a comprehensive [old-but-working] plugin:
https://sketchucation.com/pluginstore?pln=Matt_Toggle_Units
It has a toolbar and a menu you could shortcut to…
Is this sufficient ?
It’s perhaps more complicated that you want ?

1 Like

It would be possible in Applescript (Mac only) as a UI Script, but you’d see the Model Info dialog appearing and the settings changing before your eyes as if someone had taken over your computer. Sometimes this is the only way to do things in a script, like I have scripts to turn on/off the mouse hot corners. This is easier in Ruby. Here’s a simple script that only has your two options of mm with no decimal places or metres with 2 places of precision. It’s only 50 lines and it is not encrypted, so you can change the settings to suit.

UnitSwitch.rbz (1.0 KB)

Go to Tools Menu > Unit Switch > millimetres or metres:
UnitSwitch%20Menu

Search for metres to set the shortcuts:
UnitSwitch%20Shortcuts

2 Likes

Dynamic components.

If you create a component for the thing you are investigating, you can undertake any number of useful calculations using component attributes. I use this to calculate floor areas in m2, capacity of rooms etc.

The attributes can be a little awkward to initially set up, however I now have a template component which can be dropped into the model. This allows quick copying and pasting of attributes. eg: =ROUND(FACEAREA()/2*2.54 *2.54/10000,0) calculates the area of a flat rectangle, drawn in mm, and reports the value back in m2 to zero decimal places. Similarly, I can calculate capacity, or add attributes for cost/m2 and calculate overall costs per zone of the building.

There are others standard functions listed at https://help.sketchup.com/en/article/114561

Isn’t this forum a wonder? Within hours of posting, a multitude of possible solutions. Lots of good ideas but I chose @McGordon’s for its simplicity and closeness to what I was after. It is now installed and working. Thanks mucho!

The beauty of this is that it not only affects the Entity Info display but also controls how dimensions are shown.

Surely that’s worth publishing as an official SU extension?

2 Likes

Bummer! @McGordon’s plugin doesn’t work with SU 2019. I get an error message when I fire up SU.

Can it be upgraded?

Possibly…what’s the error message?

Error Loading File /Users/sevans/Library/Application Support/SketchUp 2019/SketchUp/Plugins/Matt_Toggle_Units/Toggle_Units.rb

Error: #<SyntaxError: /Users/sevans/Library/Application Support/SketchUp 2019/SketchUp/Plugins/Matt_Toggle_Units/Toggle_Units.rb:205: Invalid return in class/module body

return if not settings.include?("tr…

^~~~~~>

/Applications/SketchUp 2019/SketchUp.app/Contents/Resources/Content/Tools/extensions.rb:197:in `require’

/Applications/SketchUp 2019/SketchUp.app/Contents/Resources/Content/Tools/extensions.rb:197:in `load’

/Users/sevans/Library/Application Support/SketchUp 2019/SketchUp/Plugins/Matt_Toggle_Units.rb:62:in `register_extension’

/Users/sevans/Library/Application Support/SketchUp 2019/SketchUp/Plugins/Matt_Toggle_Units.rb:62:in `<top (required)>’

If you go to the thread on Sketchucation and look near the end of it, you’ll see that TIG has given a correction that will make the extension work fine.

Dave, that’s for the Toggle Units plugin. Mine is simpler and called Unit Switch.

Your error message indicates Matt’s Toggle Units.

Ha! I see what has happened. I actually have both plugins and neither of them works. So perhaps I could get the Toggle Units one working but I tend to use the other.

Yeah, that’s due to a change in Ruby’s syntax rules. As @DaveR noted, the general workaround is known and would just have to be applied to this specific extension. I don’t have time to do it myself today but likely someone will pitch in.

Hi,
I haven’t been using SketchUp much lately, I haven’t been on this forum for months either. I’ve installed SketchUp 2019, but haven’t moved all my extensions over yet. I don’t know what’s new if anything with the SketchUp Ruby API. I’ll have a look at this when I do.

The error messages you posted do indeed look like the other extension

Thanks for responding. Obviously, I would be delighted if either you or someone could show me how to correct the syntax to make your plugin work. I appreciate it is unlikely to be high on your priority list if you no longer use SU much yourself.

I tried the rbz that @McGordon provided above, and it works fine for me under SU 2019. @simoncbevans what error are you getting from it?

You know what? I have been a complete idiot! You’re right, Steve, it is working. I didn’t find it in the menus when I looked and having seen the error message without noticing it was actually about a plugin I don’t use, I leapt to the wrong conclusion. Sorry, sorry, everyone, I have wasted your time.

If only I could erase this whole thread and crawl under a shell…

Mac OS : This UnitSwitch (plug in/ or extension?) is a really good and useful for working in mm, but finding floor areas in m2. I somehow managed to find it (here in this thread probably) and install in SU pro 2018. For the life of me I can not remember/ replicate the install in my 2019pro


So I located my original copy of UnitSwitch.rbz (stowed in a ‘seemingly random’ folder - not within ‘SU2018 realm’), I’m not sure if/how it needs to be linked to the 2019 pro - dragged and dropped somewhere (ruby console?), linked, referenced, double clicked or ?? - Please, if there is a simple instruction - I would be grateful.
I agree this should be base menu item in SU platform.
Thx.

If you look earlier in this thread you will find the post where McGordon shared the .rbz file. Download it and install using the extension manager in SketchUp.

1 Like

that was easy, silly me. much appreciated.