In the example three drawing objects have been created in the Ruby class. Drawing objects has been created by using the new method. Parameters are entered through the input box. In this example the initialize method is declared with name, depth, width and height. Def and end are used to define a Ruby method initialize and the values of these local variables are passed to the instance variables @draw_name, @draw_depth, @draw_width and @draw_height.
Ruby Code
DRAWING_CLASS_RB
wd=UI::WebDialog.new(
"Drawings", true, "",
400, 300, 100, 100, false )
class Drawing
def initialize(name, depth, width, height)
@draw_name = name
@draw_depth = depth
@draw_width = width
@draw_height = height
end
def display_details()
UI.messagebox "ID : #{@draw_name} Depth : #{@draw_depth} Width : #{@draw_width} Height : #{@draw_height}"
end
end
wd.add_action_callback("get_data_2") do |web_dialog, action_name|
if action_name=="Add_drawing"
prompts = ["Drawing ID","Depth", "Width", "Height"]
input = UI.inputbox(prompts)
drawing1 = Drawing.new(input[0],input[1],input[2],input[3])
drawing_ID = "input[0].to_s"
drawing_depth = "input[1].to_i"
drawing_width = "input[2].to_i"
drawing_height = "input[3].to_i"
prompts = ["Drawing ID","Depth", "Width", "Height"]
input = UI.inputbox(prompts)
drawing2 = Drawing.new(input[0],input[1],input[2],input[3])
drawing_ID = "input[0].to_s"
drawing_depth = "input[1].to_i"
drawing_width = "input[2].to_i"
drawing_height = "input[3].to_i"
prompts = ["Drawing ID","Depth", "Width", "Height"]
input = UI.inputbox(prompts)
drawing3 = Drawing.new(input[0],input[1],input[2],input[3])
drawing_ID = "input[0].to_s"
drawing_depth = "input[1].to_i"
drawing_width = "input[2].to_i"
drawing_height = "input[3].to_i"
wd.add_action_callback("get_data") do |web_dialog, action_name|
if action_name=="Load_drawing"
drawing1.display_details()
drawing2.display_details()
drawing3.display_details()
end
end
end
end
It is also possible to bring drawings from other cad systems to Google SketchUp depending of the file format. One can example import a map with Google Earth terrain into SketchUp.