Component definition saving

Hi.,
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.reverse!
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 = 720.mm #Height of the cabinet
depth = 550.mm #depth of the cabinet
wd = 600.mm #width of the cabinet
thickness =18.mm #thickness of the panel
bpt= 8.mm  #thickness of the back panel
tpw = 100.mm  # top panel width
bpo = 8.mm # back panel offset
bppo = 20.mm # back panel position offset
sc = 2.mm # shelf clearance
so = 20.mm # Shelf offset
shch = 2.5.mm # Shutter Clearance height
shcv = 1.mm #Shutter clearance width
lht = 100.mm # 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] = Geom::Point3d.new(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.reverse!
face.pushpull(height, true)

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

image

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…

john

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…

john

1 Like

Thanks a lot

Hi.,

Still throws the error

image

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?

john

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

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

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