RUBY FILE
require 'sketchup.rb'
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
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"
drawing1.display_details()
drawing2.display_details()
drawing3.display_details()
HTML DIALOG
First, we define a Web Dialog instance named wd. Pressing a button opens a dialog box where you can enter the drawing information.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 FILE
require 'sketchup.rb'
wd=UI::WebDialog.new("Drawings", true, "", 400, 300, 100, 100, false )
wd.set_file( "C:/Program Files/SketchUp/SketchUp 2017/Tools/DrawDetails.html" )
wd.show()
wd.add_action_callback("inputData") {|wd, action|inputData}
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
def inputData
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"
drawing1.display_details()
drawing2.display_details()
drawing3.display_details()
end
HTML FILE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
<html>
<a href="skp:inputData@true">Input Drawing Data </a>
<head>
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Get your name from Sketchup</title>
<script language="javascript" src="js/prototype.js"></script>
<script language="javascript">
</head>
<body>
</body>
</html>