Having trouble ending a simple script
-
Hello all,
I'm trying to get from the tutorials into my first ruby plugin and am tantalizingly close but still getting a syntax error at the very end. Here's the code:
require 'sketchup' Sketchup.send_action "showRubyPanel;" UI.menu("PlugIns").add_item("Square Organ Pipe 2D") prompts = [$exStrings.GetString("Internal Width"), $exStrings.GetString("Internal Depth"), $exStrings.GetString("Thickness")] values = [0.inches, 0.inches, 0.inches] results = inputbox prompts, values, $exStrings.GetString("Pipe internal dimensions and thickness") internal_width, internal_depth, thickness = results model = Sketchup.active_model entities = model.entities outer_x = (thickness * 2) + internal_width outer_y = (thickness * 2) + internal_depth inner_x1 = thickness inner_x2 = thickness + internal_width inner_y1 = thickness inner_y2 = thickness + internal_depth center_x = thickness + (internal_width * 0.5) center_y = thickness + (internal_depth * 0.5) outer_1 = [0,0,0] outer_2 = [outer_x,0,0] outer_3 = [outer_x,outer_y,0] outer_4 = [0,outer_y,0] inner_1 = [inner_x1, inner_y1, 0] inner_2 = [inner_x2, inner_y1, 0] inner_3 = [inner_x2, inner_y2, 0] inner_4 = [inner_x1, inner_y2, 0] center = [center_x, center_y, 0] new_face = entities.add_face outer_1, outer_2, outer_3, outer_4 new_face = entities.add_face inner_1, inner_2, inner_3, inner_4 line = entities.add_line inner_1, center line = entities.add_line inner_2, center end
I'm sure I've made some silly beginner's mistake in here. Anyone see it?
FWIW, this is to produce some 2D boxes to assist in laying out the internal design of a pipe organ. They look like this:
...and I need to make nearly three hundred of them in sizes differing down to a thousandth of an inch. Whence the need to automate part of the process.
Thanks,
Rob -
Hi Bombarde, I looked at it very quickly. There are indeed some errors, but its all fixable.
First I wrapped your entire script in a module, and then put all the script into a method that I named "main". So now your script and variables will not be able to conflict with other scripts.
Second, your menu system was not implemented properly. Check out how I did it. Line 45 is the only line that actually is needed to load it into the menu.
Third, the 0.inches did not work on my system. I changed them to 0.to_l which will change it to a measurement unit.
And I also simplified your inputbox strings. I couldn't see why you needed to access the language handler, so I just removed all the language handler stuff, which is not needed.
And thats about all it took. Here it is, just save it as any file name in your plugins folder.
require 'Sketchup.rb' module Robert_Horton_box def Robert_Horton_box.main prompts = "Internal Width", "Internal Depth", "Thickness" values = [0.to_l, 0.to_l, 0.to_l] results = inputbox prompts, values, "Pipe internal dimensions and thickness" internal_width, internal_depth, thickness = results model = Sketchup.active_model entities = model.entities outer_x = (thickness * 2) + internal_width outer_y = (thickness * 2) + internal_depth inner_x1 = thickness inner_x2 = thickness + internal_width inner_y1 = thickness inner_y2 = thickness + internal_depth center_x = thickness + (internal_width * 0.5) center_y = thickness + (internal_depth * 0.5) outer_1 = [0,0,0] outer_2 = [outer_x,0,0] outer_3 = [outer_x,outer_y,0] outer_4 = [0,outer_y,0] inner_1 = [inner_x1, inner_y1, 0] inner_2 = [inner_x2, inner_y1, 0] inner_3 = [inner_x2, inner_y2, 0] inner_4 = [inner_x1, inner_y2, 0] center = [center_x, center_y, 0] new_face = entities.add_face outer_1, outer_2, outer_3, outer_4 new_face = entities.add_face inner_1, inner_2, inner_3, inner_4 line = entities.add_line inner_1, center line = entities.add_line inner_2, center end # Robert_Horton_box.main end # Module if !file_loaded?(__FILE__) UI.menu("Plugins").add_item("Rob's Box") { Robert_Horton_box.main } end file_loaded(__FILE__)
Chris
-
Chris,
Thanks so much for the help, the revised script works beautifully. Proof positive that I was and still am in way over my head.
Rob
Advertisement