A Toggle Viewer

extension
#1

Having used Sketchup as a hobbyist for a number of years I finally decided I needed to get to grips with Ruby and the API. I learn best by setting myself a challenging but do-able task so I decided to try and build a plugin to toggle between design options.

Sure you can do this with Layers but you have to turn the current layer visibility off then turn the new layer on for each change of design. You’ll also need to add a prefix to the layer name to keep the options grouped in the list. You may also have other items on one of the layers which you don’t want to hide. You can do it with Scenes but Scenes are primarily about storing views and you’ll either have to forego this facility or have the same set of scenes for each view option. With, say, five different scene views and four different designs you have twenty scene tabs to manage and sequence. I chose to add the designs to a common group and toggle one of this group to be visible at any one time.

To use the plugin:

  • select the different design options and add them as groups (or components) to the Toggle Group using the Plus button in the menu bar
  • use the First, Previous, Next, or Last buttons to shift between options. Next and Previous wrap around like a slide carousel (ask your dad)

When you’re done:

  • click on the Minus button to explode the Toggle Group back to its component groups or components

That’s it.

Here’s a video showing the idea.

Toggler

… and here’s the extension:

ptb_toggler.rbz (14.0 KB)

I would welcome any comments on whether it is felt useful, any ideas for improvement, or my coding.

[Confession time: Coming from a Swift/C# background I thought Ruby would be a doddle. I initially went down the route of turning a selection of the checkboxes in the Layers tray into pseudo radiobuttons. Layers were added to the selection by manually adding a prefix to the layer name. It worked OK and I learnt a lot. Then I had the idea of adding a dialog to allow the user to select toggle layers from a multiselect-dropdown. This led me down this track: Sketchup API => Ruby => HTML => Bootstrap => Javascript => jQuery then a blizzard of things with odd names like Skippy and Grunt. Not much fun. Finally I hit on the obvious idea of using a group as the container and had something up and running within a couple of hours. So long Skippy; goodbye Grunt.]

5 Likes

#2

Diving directly into HTML+CSS+JS if you are all new to this can be daunting when you only want a simple dialog.

Did you have a look at the HtmlDialog Inputbox example?

That lets you create a simple dialog box using only a Ruby interface if you are ok with what that example already offer.

0 Likes

#3

I did look at the HtmlDialog Inputbox but what I really wanted was a multi-select dropdown and chose the one by David Stutz. My interface as a result looked like this (I never got round to prettying the layout).

43

I exaggerated the pain somewhat in my post as I like learning new stuff. HTML and Bootstrap is really one topic and Javascript isn’t that far removed from C#. What troubled me most was when I hit an install problem with plugin code and the answer was nearly always ‘open a terminal window and type sudo followed by an alphabet soup of unix commands’.

The good thing about following this path was it forced me in the end to choose a much simpler solution.

0 Likes

#4

This is a really cool extension! The principle is simple, but the best realization is the challenge!

I know a lot of users (@g.h.hubers ) who wanted to have something where they switch visibility of objects like the Google Earth terrain/snapshot layer button:
Instead of needing two or more clicks to hide a layer and show another layer, the user could do both simultanously in one step. This is very useful for presentations (toggle between alternative states of a house).

I was struggling with putting this into a minimal UI, because (unlike the Google Earth terrain/snapshot) a user could want an arbitrary number of separate configurations (e.g. roofs, garages) with an arbitrary number of states (roof 1, roof 2, roof 3). This is not easy to realize with SketchUp’s toolbar buttons which have at most two states (enabled/disabled without changeable icons) and one cann not efficiently add/remove buttons (for separate configurations).

I like how your approach solves this with forward/backward navigation through the list of states.

0 Likes

#5

By the way, for SketchUp development you don’t really need to open a terminal (apart from the Ruby Console or Ruby Console+). For the scope of a small, simple dialog (single-page app with a single view) it is absolutely fine to focus on vanilla HTML and JavaScript.

“Modern” JavaScript tools can be a bit intimidating and confusing because of their fancy names and intransparent purpose, often one tool requires (or integrates with) another. CLI tools, automation tools like grunt/gulp, transpilers, GUI toolkits become useful once your plugin grows into a more complex app and you feel you need tools that support you handling complexity and maintainability.

2 Likes

#6

How right you are!
With large chunks of your model grouped and a meaningful layer assigned to “that chunk” group, plus having several of such groups, you could switch rapidly between groups to model in different environments(as in different groups/models/worlds). All you need is one or several group switches as icons, like the “Toggle Terrain” button.

0 Likes

#7

This is quite impressive for being a first extension.

One minor thing, the file that lies directly in the plugin folder (ptb_toggler.rb) is often referred to as the loader file. I’d rename loader.rb to e.g. main.rb to avoid any confusion.

0 Likes

#8

Many thanks to you (and Aerilius) for your kind comments and for putting me right about the loader file. I’ve corrected this as well as removing some debug lines and an obsolete EntitiesObserver class that I hadn’t spotted. Code has been corrected in original post.

Which brings me to this question. If the extension is felt to be useful what is the best way of making it available. I don’t really want to put it on the Extension Warehouse with all the support obligations that that seems to entail. I guess Github is one way to go. Any other suggestions?

0 Likes

#9

This looks great! I’ve wanted a better way to deal with managing design option presentation and thought that an options toggle would be the right approach.

Why not on the Sketchucation Plugin Store?

0 Likes

#10

Thanks for the suggestion. I’ll do just that.

0 Likes

#11

Whoops! My apologies.

In my haste to clean out the debug stuff I managed to leave in a reference to the recently deleted EntitiesObserver. This stopped things working. Code has been corrected in original post.

0 Likes

#12

Actually incorrect. It is the extension registrar file …

http://ruby.sketchup.com/Sketchup/ExtensionsManager.html says …

The ExtensionsManager class provides a way of accessing the SketchupExtensions that have been registered via the Sketchup.register_extension method.

… and by EW rule must have the same name as the author’s extension subfolder.

The loader file is what the SketchUpExtension instance points at (via it’s @path variable) in the extension’s subfolder, and is loaded via the instance’s internal load() method. (Ie, it is the pathname passed as the 2nd argument to the SketchUpExtension constructor method.)

Many author’s such as ThomThom name it some variation ending in “main”.
I myself usually used the “loader” suffix because it basically loads all the other file’s for the extension, and by personal convention I trap any LoadErrors that occur in this file.


If the user has switched off the extension, then the ExtensionManager never loads the loader file, but it always loads the registrar scripts in the “Plugins” folder proper. *

* Unless some other manager like SketchUcation’s PluginStore renames them from .rb to .rb! or whatever so as to hide them from SketchUp.

0 Likes

#13

It is preferable that there be only 1 version available in the initial post (kept up to date) rather than several of differing versions posted throughout the thread. (It’s okay to add an announcement of a new version but users normally go back to the top of the thread to get the latest.)

1 Like

#14

Thanks for the hint Dan. I’ve removed the superfluous links and updated the one in the original post.

2 Likes

#15

Great idea! This is very useful and commonly used functionality

0 Likes

#16

Very handy little piece of programming. Thanks for your good work

0 Likes