I am not versed in Ruby, but I needed a script to create a cabinet based on dimensions entered in a GUI - so I have tried to figure out how to accommodate my needs by studying other scripts to see if I could figure out how they work.
The cabinet needs to be placed as a 'group' named by a Cabinet Code entered in the GUI, and each part of the cabinet needs to be a 'sub-group' named with the Cabinet code prefixing the part name.
For example the cabinet group may be called 'Cabinet1' and the panel parts are groups called 'Cabinet1 - SideL', 'Cabinet1 - Bottom','Cabinet1 - Top' etc.
I have managed to creat the first script which is for drawing the cabinet.
Each cabinet part is created as its own 'group'. (No rocket science for most of you, but I was well pleased that I got it to work).
However I am stuck on the next 2 steps.
As I need the group for each part to be called something different for every cabinet created I have added a prompt for the cabinet code to be entered in the 'Cabinet Code' box.
My final question is, how do I create a global 'Group' for the whole cabinet before it is placed using the 'Cabinet Code' such that each of the part groups are secondary level.
require 'sketchup.rb'
def wallcab1
prompts = ["Width ", "Height ", "Depth", "Side Thickness", "Top-Bottom Thickness", "Back thickness ", "Cabinet Code"]
values = [500.mm, 720.mm, 300.mm, 18.mm, 18.mm, 18.mm, 0.mm]
results = inputbox prompts, values, "Cabinet Dimensions"
return if not results
xx, zz, yy, d1, z1, r1, n1 = results
Make Left Side
model = Sketchup.active_model
model.start_operation "SideL"
entities = model.active_entities
group = entities.add_group
entities = group.entities
pts = []
pts[0] = [0.mm, 0.mm, 0.mm]
pts[1] = [d1, 0.mm, 0.mm]
pts[2] = [d1, yy, 0.mm]
pts[3] = [0.mm, yy, 0.mm]
face = entities.add_face pts
status = face.pushpull -zz, true
group.name = "SideL"
Make Bottom Panel
model = Sketchup.active_model
model.start_operation "Bottom"
entities = model.active_entities
group = entities.add_group
entities = group.entities
pts = []
pts[0] = [0.mm+d1, 0.mm, 0.mm]
pts[1] = [xx-d1, 0.mm, 0.mm]
pts[2] = [xx-d1, yy, 0.mm]
pts[3] = [0.mm+d1, yy, 0.mm]
face = entities.add_face pts
status = face.pushpull -z1, true
group.name = "Bottom"
Make Top Panel
model = Sketchup.active_model
model.start_operation "Top"
entities = model.active_entities
group = entities.add_group
entities = group.entities
pts = []
pts[0] = [0.mm+d1, 0.mm, 0.mm+zz]
pts[1] = [0.mm+xx-d1, 0.mm, 0.mm+zz]
pts[2] = [0.mm+xx-d1, yy, 0.mm+zz]
pts[3] = [0.mm+d1, yy, 0.mm+zz]
face = entities.add_face pts
status = face.pushpull -z1, true
group.name = "Top"
Make Right Side
model = Sketchup.active_model
model.start_operation "SideR"
entities = model.active_entities
group = entities.add_group
entities = group.entities
pts = []
pts[0] = [xx-d1, 0.mm , 0.mm]
pts[1] = [xx, 0.mm, 0.mm]
pts[2] = [xx, yy, 0.mm]
pts[3] = [xx-d1, yy, 0.mm]
face = entities.add_face pts
status = face.pushpull -zz, true
group.name = "SideR"
Make Back Panel
model = Sketchup.active_model
model.start_operation "Back"
entities = model.active_entities
group = entities.add_group
entities = group.entities
pts = []
pts[0] = [0.mm, 0.mm+yy, 0.mm+zz]
pts[1] = [0.mm+xx, 0.mm+yy, 0.mm+zz]
pts[2] = [0.mm+xx, 0.mm+yy+r1, 0.mm+zz]
pts[3] = [0.mm, 0.mm+yy+r1, 0.mm+zz]
face = entities.add_face pts
status = face.pushpull -zz, true
group.name = "Back"
end
if( not file_loaded?("wallcab1.rb") )
# This will add a separator to the menu, but only once
#add_separator_to_menu("Plugins")
# To add an item to a menu, you identify the menu, and then
# provide a title to display and a block to execute. In this case,
# the block just calls the create_box function
UI.menu("Plugins").add_item("Wall Cabinet1") { wallcab1 }
end
#-----------------------------------------------------------------------------
file_loaded("wallcab1.rb")
Any help would be greatly appreciated.