Automating Sketchup workflow with ruby script


#1

I’m trying to find a way to automate this process to a single-click:

Within the styles window:

  • Under Edges:
    Enable edges
    Enable edge profiles (with a value of 1)

  • Under Face:
    Change face style to “hidden line”

  • Under Background:
    Change color to white and disable sky and ground

Then disable shadows, fog, hidden geometry, axes, guides, section planes, and section cuts from the view menu.


I’m thinking the best way to automate this is to make a ruby script, but I’m not sure. I saw someone do this with a ruby script, but the script only applies to SketchUp 8 and below.

What I’m having trouble with is finding a “road map” of sorts for how these sketchup commands look in ruby script. Is there such a thing that anyone could recommend OR is there a plugin, or extension that will show a record of what the ruby script commands look like as I perform them in sketchup (this way, I could just perform the sequence of events one time manually and then copy the resulting code into a ruby script for automation the next time)?


#2

These are all Style settings, so just make a new Style.


#3

And when you have the Style you want and you have saved it out, then your Ruby script can ‘add’ it and set it to be the active style at the same time…
http://www.sketchup.com/intl/en/developer/docs/ourdoc/styles#add_style
http://www.sketchup.com/intl/en/developer/docs/ourdoc/styles

Much easier than changing all of the bits and bobs, which will potentially be lost when the user next changes something…


#4

they are all in the API, and you can make a script that dynamically records changes, but mine only works reliably on a mac, so it’s unpublished…

these things aren’t covered by a Style setting, so they are worth saving as a Template or doing in ruby…

        # collect items not covered by Style options...
        sun4 = Sketchup.active_model.shadow_info["UseSunForAllShading"]
        shad = Sketchup.active_model.shadow_info["DisplayShadows"]
        dark = Sketchup.active_model.shadow_info["Dark"]
        light = Sketchup.active_model.shadow_info["Light"]
        faces = Sketchup.active_model.shadow_info["DisplayOnGroundPlane"]
        ground = Sketchup.active_model.shadow_info["DisplayOnAllFaces"]

here’s an example of changing some things for a rendering mode i use…

                    Sketchup.active_model.rendering_options["BackgroundColor"] = (Sketchup::Color.new(0,255,0,255))
                    Sketchup.active_model.shadow_info["UseSunForAllShading"] = true
                    Sketchup.active_model.shadow_info["DisplayOnGroundPlane"] = false
                    Sketchup.active_model.shadow_info["DisplayOnAllFaces"] = false
                    Sketchup.active_model.shadow_info["DisplayShadows"] = false
                    Sketchup.active_model.shadow_info["Dark"]  = 100
                    Sketchup.active_model.shadow_info["Light"] = 100
                    Sketchup.active_model.rendering_options["EdgeDisplayMode"] = 0

john


#5

I see. I didn’t think I could make and save styles since I don’t have the pro version. This solved my issue.

Thanks guys!


#6

Each scene page in the model can have it’s own style applied. If you have the Scene Tabs visible, you can quickly switch between various views of the model each in a different style.