Component definition saving

I am practicing a ruby file from Automatic Sketchup book with the following code, creation of component definition and saving.

# Create the component definition
list = Sketchup.active_model.definitions
comp_def = list.add "Cube"
comp_def.description = "This is a simple cube-shaped component."
# Add entities to the component definition
ents = comp_def.entities
face = ents.add_face [0,0,0], [1,0,0], [1,1,0], [0,1,0]
face.pushpull 1
# Save the component definition
save_path = Sketchup.find_support_file "Components", ""
comp_def.save_as(save_path + "/cube.skp")
puts "The definition was saved to: " + comp_def.path

help_file = Sketchup.find_support_file("help.html", "Plugins/") , 

Where the syntax for the find_support_file method -> folder name and an empty string & from the Ruby api, the filename followed by the folder name.

Which one is correct to follow.?

Also when try to follow the API, the following error i am getting for the code, which i try to execute.

mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
#declaration of variables
height = #Height of the cabinet
depth = #depth of the cabinet
wd = #width of the cabinet
thickness #thickness of the panel
bpt=  #thickness of the back panel
tpw =  # top panel width
bpo = # back panel offset
bppo = # back panel position offset
sc = # shelf clearance
so = # Shelf offset
shch = # Shutter Clearance height
shcv = #Shutter clearance width
lht = # leg height.

#Create the component definition
list = Sketchup.active_model.definitions
comp_def = list.add "LH Panel"
comp_def.description  = "this the left hand side panel"
pt = [0,1,2,3]
# referencing early point for drawing. relative coordiante ssytem
pt[0] =,0,0)
pt[1] = pt[0] + [thickness,0,0] 
pt[2] = pt[1] + [0,depth,0] 
pt[3] = pt[2] + [-thickness,0,0]

#creation of face - LH Side panel
#Add enitities to the component definition
ents = comp_def.entities
face = ents.add_face(pt)
face.pushpull(height, true)

#save the component definish
save_path = Sketchup.find_support_file ("/LH.skp", "Components")


where i am making the mistake or i am understanding wrongly.?

“Mind the Gap” as the announce on the tube…

a space between method(arg) was tolerated on earlier windows version of ruby…


Ok. Thanks
My save_as syntax is correct??

I didn’t try your code…

your error message points to a closing bracket ) on line number 43…

it is unexpected because it doesn’t end your call, i.e. it’s broken due to a syntax error…

if you paste your broken line 43 into Ruby Console, you can also test and see if you need the forward slash or not…

yes, the syntax is correct, but it implies your planing to over-write an existing component at that path…

if it’s a new file, I would use File.join(comps_path, sub_folder, new_name) after defining those…


1 Like

Thanks a lot


Still throws the error


any suggestion…

you may have a permissions issue if running things on different drives…

I’m on a mac and never run code from one with SU on another…

does it run if copy pasted directly into Ruby Console?


if i run from the console., it executes properly,

So your meaning that, it should run from the c:\ where the sketchup has installed.?

is it possible to display the component in the current model window.