New to Learning Ruby for SketchUp

O.k. it took me almost three hours to find/fiqure out, (guess at) from the Sketchup Ruby API and searching the Ruby API Community this line of code. And it wasn’t in the Automatic Sketchup book.

is_on = Sketchup.active_model.rendering_options[“EdgeDisplayMode”] = true

First, I need a ruby mentor. Any volunteers? Anyone have a goto to meeting tutorial service? There just are not enough videos on the web, beyond the basics. I live in Tampa, Florida, are there any programmers in my area?

Second, where are all the model rendering options [Keyword] settings, documented parameters for the different render options?

I know many of you have been coding for years, and there is a lot to this. I have been using Sketchup in architecture since 2003 and want to learn ruby for sketchup. For now I’m reading the Automatic Sketchup book.


Search this forum for “learn ruby” and you will find multiple topics with links to resources for learning Ruby within SketchUp and discussions of ways to go about it.

As to a mentor, you can post specific questions here and numerous experts will jump in to help you for free. As to a face-to-face in the Tampa area, I’m afraid that unless one happens to see this topic you are on your own.

The SketchUp Ruby API documents are notorious for various flaws, and failing to list the available OptionsProviders and their settings is one of these. One generally has to reverse-engineer the list by probing a model with varying settings to see what keys and values result.

Try this in the Ruby Console:

ros=Sketchup.active_model.rendering_options; ros.collect{|n| n }.sort.each{|k| puts "\"#{k}\" = #{ros[k]} [#{ros[k].class}]" };puts

prints an order list of the options by:
name = current_value [value-type]


Wow! Many thanks for that script. I also found the post “How do I start a Batch” and your reply to that question. Very helpful.

Note that @TIG’s code snippet will show you the current settings. It won’t (and can’t) show you what other values are allowable for each option. They aren’t officially listed anywhere. Lord knows why, as the OptionsProviders are exposed through the Ruby API!

However, all the options are controlled by one or another SketchUp setting. So, set the model the way you like and then run the Ruby snippet to see what values correspond. That’s what I meant by “probing the model with various settings”.


Using TIG’s snippet I see the output and understand what you mean now. I also ran across something called scraping earlier today. Don’t really know what it does, but I’m guessing something like TIG’s render option snippet.
I have a list of render options that I can work with now in the ruby code editor. Any suggestions how to create a new style based on my defined list?


fill in your profile so we at least know what platform your on…

I have a script that puts all the shadow and rendering option into an interactive WebDialog so that I can play around and find useable parameters…

it uses sliders for colours so only works on some PC’s depending on IE version used…

whenever you make a change it reports the code used so you can reuse it in a script…


Once I realized that you are specifically interested in RenderingOptions, I see that the Ruby API doc page for that particular OptionsProvider does list the available keys but not the corresponding legal values for each key. So you still have to probe…

In the Ruby API, there is a strange relationship between RenderingOptions and Style. Setting a Style immediately sets the RenderingOptions for the active model. Conversely, setting a RenderingOption immediately alters the current active Style in the model. But there is no way to create a new Style via the API (other than telling the model’s Styles collection to load one from an existing style file), no way to save a Style separately from the model, and no direct way to get or set the options associated with a particular Style. You always have to go through the active model and its Styles collection to select a Style and then through the active_model’s ROs to deal with the settings.

One way would be to manually set a Style the way you want and then use a variation of TIG’s snippet to capture rather than print the current RO values (that’s essentially what is meant by “scraping”). You could then copy that suite into your Ruby code and thence set it into the RO to force your preferred settings. The changes will persist until the user chooses a different Style or manually edits the active Style. Styles are saved in the skp file, so if the model is saved while your settings are active they will be restored the next time you open the model.

To use the SketchUp Ruby API, one must learn standard Ruby first.

The SketchUp Ruby API is just an extension to Ruby that adds modules and classes that interface with SketchUp.

There are many books and tutorials, available online for free, as well as innumerable Ruby programming books for sale. You can spend 50 dollars on a good programming Ruby book that explains more than you’ll ever need to know, or pay someone like me 50 dollars an hour to teach you a few basic things that will only scratch the surface.
What do think is better? << rhetorical question

To this end, and because this is such a common question, … I created a (“sticky”) pinned topic in this (Developers > Ruby API) category:

FYI, the SketchUp Ruby API Documentation is a programming dictionary (aka reference,) not a tutorial, nor a learning document. (It is not the owner of SketchUp’s job or responsibility to teach programming.) So, beware of the sample code in the API docs, they are notorious for typos, mistakes and often are a frivolous example of what the method does.

That book really needs to be updated. It’s old. (The original edition examples does not follow shared environment best practices, such as module wrapping.)

I never suggest reading that book first. Always suggest the good ol’ “Pick Axe” book on standard Ruby, ie “Programming Ruby - The Pragmatic Programmer’s Guide” first.

1 Like