How do I start a batch?

I am writing my first ruby script, and barely know anything, but I am trying to write a batch script that converts 2015 .skp’s to Version 7. Yes, I still use Sketchup 7. :slight_smile: I have found this code for the change…

model = Sketchup.active_model
status = model.save(“”, Sketchup::Model::VERSION_7)

I would also like to change all the units to architectural, with 1/64" settings…

Sketchup.active_model.options[“UnitsOptions”][“LengthFormat”]=1
Sketchup.active_model.options[“UnitsOptions”][“LengthUnit”]=1
Sketchup.active_model.options[“UnitsOptions”][“LengthPrecision”]=6
Sketchup.active_model.options[“UnitsOptions”][“LengthSnapLength”]=0.015625

But how do I make a batch start/script to do this for all the files in a given folder?
I have looked at TIG’s batch file that batch converts files, but I don’t understand any of it. How do I start a batch with my settings?
Thank you.

I have made several batch processing scripts, for import, export and option-changes…
All you do in your case is to add the model.options changes, then the save to v7…
Here’s an example.
You may use it for inspiration…
I have annotated it to explain what’s going on…
TIG-batch.rb (2.6 KB)

Wow TIG !! Thank you. I am studying it now…

Thank you so much TIG. Please write a book or something. :slight_smile: I do have the Automatic Sketchup book, but I seem to learn more from yours, and others scripts, more efficiently. Now, I am learning to add on to this; purge unused, setting up my own style, with no shadows…

info = Sketchup.active_model.shadow_info
info[“DisplayShadows”] = false
info[“DisplayOnGroundPlane”] = true

Sketchup.active_model.rendering_options[“BackgroundColor”] = 210,208,185
Sketchup.active_model.rendering_options[“BandColor”] = 0,0,0
Sketchup.active_model.rendering_options[“ConstructionColor”] = 0,0,0
Sketchup.active_model.rendering_options[“DepthQueWidth”] = 4
Sketchup.active_model.rendering_options[“DisplayColorByLayer”] = false
Sketchup.active_model.rendering_options[“DisplayDims”] = true
Sketchup.active_model.rendering_options[“DisplayFog”] = false
Sketchup.active_model.rendering_options[“DisplayInstanceAxes”] = false
Sketchup.active_model.rendering_options[“DisplaySketchAxe”] = true
Sketchup.active_model.rendering_options[“DisplayText”] = true
Sketchup.active_model.rendering_options[“DisplayWatermarks”] = true
Sketchup.active_model.rendering_options[“DrawDepthQue”] = false
Sketchup.active_model.rendering_options[“DrawGround”] = false
Sketchup.active_model.rendering_options[“DrawHidden”] = false
Sketchup.active_model.rendering_options[“DrawHorizon”] = true
Sketchup.active_model.rendering_options[“DrawLineEnds”] = false
Sketchup.active_model.rendering_options[“DrawProfilesOnly”] = false
Sketchup.active_model.rendering_options[“DrawSilhouettes”] = false
Sketchup.active_model.rendering_options[“DrawUnderground”] = true
Sketchup.active_model.rendering_options[“EdgeColor”] = 1
Sketchup.active_model.rendering_options[“EdgeDisplay”] = 1
Sketchup.active_model.rendering_options[“EdgeType”] = 0
Sketchup.active_model.rendering_options[“ExtendLines”] = false
Sketchup.active_model.rendering_options[“FaceBackColor”] = 171,176,204
Sketchup.active_model.rendering_options[“FaceColor”] = 0
Sketchup.active_model.rendering_options[“FaceFrontColor”] = 255,255,255
Sketchup.active_model.rendering_options[“FogColor”] = 0,0,0
Sketchup.active_model.rendering_options[“FogEnd”] = -1
Sketchup.active_model.rendering_options[“FogStart”] = -1
Sketchup.active_model.rendering_options[“FogUseBkColor”] = true
Sketchup.active_model.rendering_options[“ForegroundColor”] = 0,0,0
Sketchup.active_model.rendering_options[“GroundColor”] = 210,208,185
Sketchup.active_model.rendering_options[“GroundTransparency”] = 50
Sketchup.active_model.rendering_options[“HideConstructionGeometry”] = false
Sketchup.active_model.rendering_options[“GroundColor”] = 210,208,185
Sketchup.active_model.rendering_options[“HorizonColor”] = 255,255,255
Sketchup.active_model.rendering_options[“InactiveHidden”] = false
Sketchup.active_model.rendering_options[“InstanceHidden”] = false
Sketchup.active_model.rendering_options[“JitterEdges”] = false
Sketchup.active_model.rendering_options[“LineEndWidth”] = 9
Sketchup.active_model.rendering_options[“LineExtension”] = 3
Sketchup.active_model.rendering_options[“LockedColor”] = 255,0,0
Sketchup.active_model.rendering_options[“MaterialTransparency”] = true
Sketchup.active_model.rendering_options[“ModelTransparency”] = false
Sketchup.active_model.rendering_options[“Render”] = 2
Sketchup.active_model.rendering_options[“SectionActiveColor”] = 255,135,0
Sketchup.active_model.rendering_options[“SectionCutWidth”] = 3
Sketchup.active_model.rendering_options[“SectionDefaultCutColor”] = 0,0,0
Sketchup.active_model.rendering_options[“SectionInactiveColor”] = 112,105,97
Sketchup.active_model.rendering_options[“ShowViewName”] = true
Sketchup.active_model.rendering_options[“SilhouetteWidth”] = 2
Sketchup.active_model.rendering_options[“SkyColor”] = 189,209,208
Sketchup.active_model.rendering_options[“TexturetrueTransparency”] = 0

styles = Sketchup.active_model.styles
status = styles.purge_unused

materials = Sketchup.active_model.materials
status = materials.purge_unused

layers = Sketchup.active_model.layers
status = layers.purge_unused

components = Sketchup.active_model.components
status = components.purge_unused

1 Like

The example I gave was cut down to make it clearer…


I would certainly recommend you do that purging - but remember to purge the components first, as they can lock-up some otherwise unused materials/layer and stop them purging…
After unused components are gone the now truly unused materials/layers will purge too.


You could also make and save your own Style into the Styles Browser collection, then in other SKP files you just load and use that, rather than changing all of the shadows and rendering options one by one manually…

Thank you again, TIG.

It’s maybe not really a serious issue in SketchUp, but in terms of programming style it would be better to get once a reference to the model and re-use that, like

model = Sketchup.active_model # At the earliest point
info = model.shadow_info
…

or

command = UI::Command.new("My Batch Processor"){
  start_batch_process(Sketchup.active_model)
}
…
def start_batch_process(model)
  info = model.shadow_info
  …
end

By Sketchup.active_model you tell SketchUp “Give me a reference to whatever model is currently active”. If there can be more than one answer to this (several opened models in the same SketchUp process), the user could theoretically switch to another model and make that active, and Sketchup.active_model would suddenly give a different model. Although practically in SketchUp only the OS X version can open multiple models (and even then a script rarely encounters an active model switch), that assumption is not mathematically/logically safe. The API has been designed for a multiple document interface (and SketchUp could at any time implement that feature in the Windows version as well), so it’s better to follow the contract that the API gives (and not practical experience).`

When doing programming, we avoid assumptions as much as possible.
Is … the case?Is it guaranteed that … is always the case?