Relative coordinate input through Ruby

Hi.,
Normally the input to the sketchup from ruby code is in absolute coordinate system.,

Could anyone guide or throw some light, how to input the values in relative coordinate system in ruby.

the below code is absolute coordinate system.


# Default code, use or delete...
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
# Left side Panel
pt = [0,1,2,3]
pt[0] = [0,0,0]
pt[1] = [thickness,0,0]
pt[2] = [thickness,depth,0]
pt[3] = [0,depth,0]

#creation of face - LH Side panel
face = ent.add_face(pt)
face.reverse!
face.pushpull(height, true)
lh_group = ent.add_group face.all_connected
lh_group.name= "LH Panel"

Thanks

A point relative to what ?

It would help us help you if you explain a bit more about what you are trying to do.

Hi Dan.,

The point relative to earlier coordinate position. Since in the ruby scripting, we have to give the coordinate in the array, which has been taken by the sketchup in absolute coordinate system for drawing the entities.
Would like sketchup to get the inputs from ruby in terms of relative coordinate system.

Ex: want to draw face of 18mm thk and 550 mm depth.
so the input of coordinates (x,y,z) is something similar to
0,0,0 # starts from origin
18,0,0 # draws a line at x axis of length of 18mm from origin
0,550,0 # draws a line at y axis of length 550 mm from earlier position
-18,0,0 # draws a line at x axis of length -18 mm from earlier position (negative x axis)
0,-550,0 # draws a line at y axis of length - 550 mm from earlier position (negative (y axis)

thanks

#"Absolute"
pt[0] = [0,0,0] 
pt[1] = [thickness,0,0] 
pt[2] = [thickness,depth,0] 
pt[3] = [0,depth,0]
#"Relative"
#####pt[0] = [0,0,0]  Edited
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]
1 Like

Thanks dezmo,

Is there is any other simple solution than this, instead of adding the array

Sure, a lot:

e.g.
http://ruby.sketchup.com/Geom/Point3d.html#offset-instance_method

or
e.g.
http://ruby.sketchup.com/Geom/Point3d.html#x=-instance_method
http://ruby.sketchup.com/Geom/Point3d.html#y=-instance_method
http://ruby.sketchup.com/Geom/Point3d.html#z=-instance_method

1 Like

Thanks a lot:)