###--------------------------------------------------------------------- # Name : Grow.rb # Description : Plugins>Grow - Copy, Rotate & Scale selected objects... # Author : TIG (c) 2007 # Usage : Move/Place Objects, Select them and pick Grow. # Enter desired data and see results. Undo is in one go. # Ungrouped Faces and Edges can stick together after 'Growing'. # Play around to see types of results... # Shape, location, scale etc all produce different results... # Probably can form the basis of lots of new tools... # Version : 1.0 20070207 First issue. ###--------------------------------------------------------------------- require 'sketchup.rb' ### #################################################################### class Grow def Grow::run model = Sketchup.active_model model.start_operation "Grow" entities = model.active_entities ss = model.selection if ss.empty? Sketchup::set_status_text("GROW: NO SELECTION ! ", SB_PROMPT) UI.messagebox("Grow: No Selection ! ") return nil end group = entities.add_group(ss) ctrans = group.transformation cpoint = ctrans.origin compx = cpoint.x compy = cpoint.y compz = cpoint.z cinsert = [0,0,0]###[compx,compy,compz]### ### get current units currentunits1=Sketchup.format_length 120000 currentunits2=Sketchup.format_length 1 units = "???" ### default if currentunits1.to_s.split(".")[0].split(",")[0].split("'")[0].split("\"")[0].split("c")[0].split("m")[0] == "120000" units = "inches" end if currentunits1.to_s.split(".")[0].split(",")[0].split("'")[0].split("\"")[0].split("c")[0].split("m")[0] == "10000" units = "feet" end if currentunits1.to_s.split(".")[0].split(",")[0].split("'")[0].split("\"")[0].split("c")[0].split("m")[0] == "3048000" units = "mm" end if currentunits1.to_s.split(".")[0].split(",")[0].split("'")[0].split("\"")[0].split("c")[0].split("m")[0] == "304800" units = "cm" end if currentunits1.to_s.split(".")[0].split(",")[0].split("'")[0].split("\"")[0].split("c")[0].split("m")[0] == "3048" units = "m" end if currentunits2 == "1\"" units = "inches or ' \" " end ### show VCB and status info Sketchup::set_status_text(("GROW... PARAMETERS (" + units + ")..." ), SB_PROMPT) Sketchup::set_status_text(" ", SB_VCB_LABEL) Sketchup::set_status_text(" ", SB_VCB_VALUE) ### defaults and 1st dialog if not @xspace if units[-1,1] == "m" ### metric units so these are in mm @xspace = 0.mm @yspace = 0.mm @zspace = 150.mm else ### not metric so these are in feet @xspace = 0.feet @yspace = 0.feet @zspace = 0.5.feet end #if @xcopies = 0 @ycopies = 0 @zcopies = 10 @xrotate = 0.0 @yrotate = 0.0 @zrotate = 36.0 @xscale = 1.0 @yscale = 1.0 @zscale = 1.0 end prompts = [("X Spacing (" + units + ") : "), ("Y Spacing (" + units + ") : "), ("Z Spacing (" + units + ") : "), "X Number of Copies : ", "Y Number of Copies : ", "Z Number of Copies : ", "X Rotation (deg) : ", "Y Rotation (deg) : ", "Z Rotation (deg) : ", "X Scaling : ", "Y Scaling : ", "Z Scaling : "] value = [ @xspace, @yspace, @zspace, @xcopies, @ycopies, @zcopies, @xrotate, @yrotate, @zrotate, @xscale, @yscale, @zscale ] results = inputbox prompts, value, ("Grow Parameters (" + units + ")") if not results group.explode return nil end#if @xspace = results[0] @yspace= results[1] @zspace= results[2] @xcopies = results[3] @ycopies = results[4] @zcopies = results[5] @xrotate = results[6] @yrotate = results[7] @zrotate = results[8] @xscale = results[9] @yscale = results[10] @zscale = results[11] @xcopies = 0 if @xspace == 0.0 @ycopies = 0 if @yspace == 0.0 @zcopies = 0 if @zspace == 0.0 @xspace = 0.0 if @xcopies == 0 @yspace = 0.0 if @ycopies == 0 @zspace = 0.0 if @zcopies == 0 ### loop through to make copies ### xscale = 1; yscale = 1; zscale = 1 xspace = @xspace; yspace = @yspace; zspace = @zspace copies = [] xrot=0; yrot=0; zrot=0 x = 0.0 0.upto(@xcopies) do |this| y = 0.0 0.upto(@ycopies) do |that| z = 0.0 0.upto(@zcopies) do |the_other| ### move/copy xx = x + compx; yy = y + compy; zz = z + compz point = Geom::Point3d.new(xx,yy,zz) transform = Geom::Transformation.new(point) e = group.copy e.move!(transform) ### move p = Geom::Point3d.new(cinsert.transform(e.transformation)) v = Geom::Vector3d.new(1,0,0) r = Math::PI * xrot / 180 xrot = xrot + @xrotate rotate = Geom::Transformation.rotation(p,v,r) e.transform!(rotate) v = Geom::Vector3d.new(0,1,0) r = Math::PI * yrot / 180 yrot = yrot + @yrotate rotate = Geom::Transformation.rotation(p,v,r) e.transform!(rotate) v = Geom::Vector3d.new(0,0,1) r = Math::PI * zrot / 180 zrot = zrot + @zrotate rotate = Geom::Transformation.rotation(p,v,r) e.transform!(rotate) ### scale sx = xscale; sy = yscale; sz = zscale scaler = Geom::Transformation.scaling(p,sx,sy,sz) e.transform!(scaler) xscale = xscale * @xscale yscale = yscale * @yscale zscale = zscale * @zscale ### add to array copies.push(e) ### update paramerers zspace = zspace * @zscale z = z + zspace end #upto yspace = yspace * @yscale y = y + yspace end #upto xspace = xspace * @xscale x = x + xspace end #upto ### remove 'spare' original group... group.erase! copies.each{|e|e.explode} ### commit for total undo model.commit_operation end #def end #class ### menu #### ######################################################### if(not file_loaded?("Grow.rb"))### UI.menu("Plugins").add_separator UI.menu("Plugins").add_item("Grow"){Grow.run} end file_loaded("Grow.rb") ### ####################################################################