Hi everyone,
I am quite new to SketchUp and Ruby so not too sure on a few things.
I’ve made a plugin for a project I’m working on for myself everything works as needed but this it where it gets tricky.
I’m trying to “automate” the creation of a basic design (a room). If you select the plugin in the menu it will generate the design, but I want to find out if there is a way to execute this via code (without manually clicking the plugin).
So basically I want to open SketchUp from code and then execute generation of the design. Is this possible?
Apologies if my explanation is not the best.
Thanks in advance.
There are ways to launch SU and run a script, this is the mac way from Terminal.app…
/Applications/SketchUp\ 2016/SketchUp.app/Contents/MacOS/SketchUp /tmp/abc.skp --args -RubyStartup /tmp/test_ruby.rb
but, it will give an error without a .skp and your objective then seems a strange way to open what is basically a ‘Template’…
A more common approach would be to create the ‘basic room’ in an empty skp and then use ‘File >> Save As Template’
then open the pre-saved template
/Applications/SketchUp\ 2016/SketchUp.app/Contents/MacOS/SketchUp --args -template /tmp/abc.skp
while both of these work, they open a new instance [like on a PC] and take a while to load…
if the .skp is set as your default Template, then just use open -a SketchUp
in your launcher…
It doesn’t even need to be saved as a Template as long as you rename your new versions…
then just use open /tmp/abc.skp
in your launcher…
john
Thank you for your reply John.
The reason I want to do this is because I want to dynamically create a given amount of rooms, and once that is done save the file and send it via email.
having ruby as a toolbar item inside SU is the easiest way to generate anything that needs to be dynamic…
using an external app that then needs to control SU is an added layer of complexity… [I have written them, ahhhh]
most of my early stuff used Applescript or Automator to do this type of thing but rewriting them as plugins made them far more stable…
if you want to post what you’ve got I and others will offer more informed advice…
john
This is what I have at the moment.
require ‘sketchup.rb’
#variables
run = 157.48
width = 157.48
height = 106.299
thickness = 5.905512
model = Sketchup.active_model
entities = model.entities
x1 = 0
x2 = width
y1 = 0
y2 = run
z = 0
pt1 = [x1, y1, z]
pt2 = [x2, y1, z]
pt3 = [x2, y2, z]
pt4 = [x1, y2, z]
t1 = [(x1 + thickness), (y1 + thickness), z]
t2 = [(x2 - thickness), (y1 + thickness), z]
t3 = [(x2 - thickness), (y2 - thickness), z]
t4 = [(x1 + thickness), (y2 - thickness), z]
new_face = entities.add_face pt1, pt2, pt3, pt4
new_face.pushpull (height * -1)
inner_face = entities.add_face t1, t2
So basically I have a web service that the user will input how many rooms etc, and on the server it will open SketchUp create the rooms accordingly and then email the file to the user for small tweaks if needed.
you need to check the TOS on that one, there are rules about some types of automation…
it would more common to provide a plugin for the users SU, it can link to your server to generate and download the script too create the geometry locally…
or it has a library of skps and it inserts them based on the users choices…
there are lots of readable examples out there to see how others have done it before…
john
IMO, that violates the license terms. (paraphrased) You cannot have other people running your licensed copy of SketchUp (even if some script sits between them and your SketchUp.) But that does not mean you might not get a written permission to do so.
Downloadable dynamic components, or a client-side plugin, are a lot easier.
run = 157.48
width = 157.48
height = 106.299
thickness = 5.905512
defaults = [run,width,height,thickness]
prompts = %w{run width height thickness}
caption = "Enter Room Size"
results = UI.inputbox(prompts,defaults,caption)
if results
run,width,height,thickness = results
end
OK perfect will look into it, thank you guys for your feedback it is greatly appreciated.