# Created by Bojan Mitrovic (c) 2012 require 'sketchup.rb' def daft(dialog) mod = Sketchup.active_model # Open model ent = mod.entities # All entities in model sel = mod.selection # Current selection if sel.count>0 mod.start_operation("Dafting", false) origin = Geom::Point3d.new 0,0,0 xAxis = Geom::Vector3d.new 1,0,0 yAxis = Geom::Vector3d.new 0,1,0 zAxis = Geom::Vector3d.new 0,0,1 # Transformations # Dimension 1 (D1) defs tx1 = dialog.get_element_value("tx1").to_f ty1 = dialog.get_element_value("ty1").to_f tz1 = dialog.get_element_value("tz1").to_f rx1 = dialog.get_element_value("rx1").to_f ry1 = dialog.get_element_value("ry1").to_f rz1 = dialog.get_element_value("rz1").to_f sx1 = dialog.get_element_value("sx1").to_f sy1 = dialog.get_element_value("sy1").to_f sz1 = dialog.get_element_value("sz1").to_f ni1 = dialog.get_element_value("ni1").to_f tv1 = Geom::Vector3d.new tx1,ty1,tz1 tt1 = Geom::Transformation.translation tv1 rtx1 = Geom::Transformation.rotation origin, xAxis, rx1.degrees rty1 = Geom::Transformation.rotation origin, yAxis, ry1.degrees rtz1 = Geom::Transformation.rotation origin, zAxis, rz1.degrees st1 = Geom::Transformation.scaling sx1, sy1, sz1 t1 = tt1 * rtx1 * rty1 * rtz1 * st1 # Dimension 2 (D2) defs tx2 = dialog.get_element_value("tx2").to_f ty2 = dialog.get_element_value("ty2").to_f tz2 = dialog.get_element_value("tz2").to_f rx2 = dialog.get_element_value("rx2").to_f ry2 = dialog.get_element_value("ry2").to_f rz2 = dialog.get_element_value("rz2").to_f sx2 = dialog.get_element_value("sx2").to_f sy2 = dialog.get_element_value("sy2").to_f sz2 = dialog.get_element_value("sz2").to_f ni2 = dialog.get_element_value("ni2").to_f tv2 = Geom::Vector3d.new tx2,ty2,tz2 tt2 = Geom::Transformation.translation tv2 rtx2 = Geom::Transformation.rotation origin, xAxis, rx2.degrees rty2 = Geom::Transformation.rotation origin, yAxis, ry2.degrees rtz2 = Geom::Transformation.rotation origin, zAxis, rz2.degrees st2 = Geom::Transformation.scaling sx2, sy2, sz2 t2 = tt2 * rtx2 * rty2 * rtz2 * st2 # Loop D1 objects = ent.add_group(sel) newObjects = objects.copy objects.explode (0..ni1-1).each do |i1| # Loop D2 newObjectsD2 = newObjects.copy (0..ni2-1).each do |i2| objects = newObjectsD2.transform! t2 if i2!=ni2-1 newObjectsD2 = objects.copy end objects.explode end objects = newObjects.transform! t1 newObjects = objects.copy objects.explode end # Loop D2 newObjectsD2 = newObjects.copy (0..ni2-1).each do |i2| objects = newObjectsD2.transform! t2 if i2!=ni2-1 newObjectsD2 = objects.copy end objects.explode end newObjects.explode mod.commit_operation else UI.messagebox "Select objects before operation!" end end def daft_callDialog dlg_html ='' dlg_html+='' dlg_html+='' # D1 dlg_html+='

' dlg_html+='tx1:  ' dlg_html+='ty1:  ' dlg_html+='tz1: ' dlg_html+='

' dlg_html+='

' dlg_html+='rx1:  ' dlg_html+='ry1:  ' dlg_html+='rz1: ' dlg_html+='

' dlg_html+='

' dlg_html+='sx1:  ' dlg_html+='sy1:  ' dlg_html+='sz1: ' dlg_html+='

' dlg_html+='

' dlg_html+='ni1: ' dlg_html+='

' dlg_html+='
' # D2 dlg_html+='

' dlg_html+='tx2:  ' dlg_html+='ty2:  ' dlg_html+='tz2: ' dlg_html+='

' dlg_html+='

' dlg_html+='rx2:  ' dlg_html+='ry2:  ' dlg_html+='rz2: ' dlg_html+='

' dlg_html+='

' dlg_html+='sx2:  ' dlg_html+='sy2:  ' dlg_html+='sz2: ' dlg_html+='

' dlg_html+='

' dlg_html+='ni2: ' dlg_html+='

' dlg_html+='
' dlg_html+='

daft | undo | ' dlg_html+='daft applet | ' dlg_html+='Generic explorations lab

' dlg_html+='' dlg_html+='' dlg = UI::WebDialog.new('Daft Control Panel', true, 'DDialog', 375, 550, 150, 150, true) dlg.navigation_buttons_enabled = false dlg.set_html(dlg_html) dlg.add_action_callback("daft_call") {|dialog, action| daft(dialog) } dlg.add_action_callback("daft_undo") {|dialog, action| Sketchup.undo } dlg.show end UI.menu("PlugIns").add_item("DAFT") { daft_callDialog } #daft_callDialog