Now the Penny is dropping! Slowly...
After a day going round in circles, I've had a productive evening...
For absolute Newbies, here are some Group transformations (thanks yet again TIG):
# 30/04/2011 SJH_Groups_Add_v03.rb
puts "Running... SJH_Groups_Add"
require 'sketchup.rb'
model = Sketchup.active_model
entities = model.entities
#entities = model.active_entities
selection = model.selection
# Set some length variables
rl = 1
gl = 1
bl = 1
rlmid = rl*0.5
glmid = gl*0.5
blmid = bl*0.5
# To convert to SU current Model units
rl = rl.to_s.to_l
gl = gl.to_s.to_l
bl = bl.to_s.to_l
rlmid = rlmid.to_s.to_l
glmid = glmid.to_s.to_l
blmid = blmid.to_s.to_l
# Create Face points array
fpts = []
fpts[0] = [0, 0, 0]
fpts[1] = [rl, 0, 0]
fpts[2] = [rl, gl, 0]
fpts[3] = [0, gl, 0]
# Create String and counter for incrementing group names
sjhname = "SJHGroup"
groupcount = 0
# ---------- Start Main Code ----------
groupcount+= 1
groupname = sjhname + groupcount.to_s
# Create a Group - mygroup1
mygroup1 = [] # Create an empty array to prevent Bug Splat!
mygroup1 = entities.add_group # Make the array a Group Entities class
gentities1 = mygroup1.entities # Create an array of the Entities in mygroup
mygroup1.name = groupname # Change the Group name
face = gentities1.add_face fpts # Add a face to gentities1
pullface = face.pushpull -bl # Do a push/pull to the face
tcoordinates = [rlmid, glmid, blmid] # Set coordinates for text
tpoint = Geom;;Point3d.new tcoordinates # Create a 3d point for text
mytext = gentities1.add_text "#{groupname}", tpoint # Add a text label
model.close_active # Close mygroup1
# Closed the Group
UI.messagebox("mygroup1 added. What's next?") # User Message to see what happened!
# Move everything in the model
entlen = entities.length
transform = Geom;;Transformation.new([(rl*2),0,0])
for e in (0... entlen)
entities.transform_entities(transform, entities[e])
end
# Select mygroup1
#selection.add(mygroup1)
UI.messagebox("All entities moved. What's next?") # User Message to see what happened!
groupcount+= 1
groupname = sjhname + groupcount.to_s
# Create a Group - mygroup2
mygroup2 = [] # Create an empty array to prevent Bug Splat!
mygroup2 = entities.add_group # Make the array a Group Entities class
gentities2 = mygroup2.entities # Create an array of the Entities in mygroup
mygroup2.name = groupname # Change the Group name
face = gentities2.add_face fpts # Add a face to gentities2
pullface = face.pushpull -bl # Do a push/pull to the face
tcoordinates = [rlmid, glmid, blmid] # Set coordinates for text
tpoint = Geom;;Point3d.new tcoordinates # Create a 3d point for text
mytext = gentities2.add_text "#{groupname}", tpoint # Add a text label
model.close_active # Close mygroup2
# Closed the Group
UI.messagebox("mygroup2 added. What's next?") # User Message to see what happened!
# Move everything in the model
entlen = entities.length
transform = Geom;;Transformation.new([(rl*2),0,0])
for e in (0... entlen)
entities.transform_entities(transform, entities[e])
end
# Select mygroup
#selection.add(mygroup2)
UI.messagebox("All entities moved. What's next?") # User Message to see what happened!
# Move (mygroup1) ONLY
# Try making it as a proper transformation (TIG 30/04/2011)
pt=Geom;;Point3d.new(rl*2, 0, 0)
tr=Geom;;Transformation.new(pt)
mygroup1.transform!(tr)
UI.messagebox("mygroup1 moved by Point3d. What's next?") # User Message to see what happened!
# Move (mygroup2) ONLY
# To move by a set vector use (TIG 30/04/2011)
vt=Geom;;Vector3d.new(-rl*2, 0, 0)
tr=Geom;;Transformation.translation(vt)
mygroup2.transform!(tr)
UI.messagebox("mygroup2 moved by Vector3d. What's next?") # User Message to see what happened!
# Rotate (mygroup1) along Red axis
pt=Geom;;Point3d.new(0, 0, 0)
vt=Geom;;Vector3d.new(rl, 0, 0)
an=45.degrees
tr=Geom;;Transformation.rotation(pt,vt,an)
mygroup1.transform!(tr)
UI.messagebox("mygroup1 rotated along Red axis. What's next?") # User Message to see what happened!
# Rotate (mygroup1) along Green axis
pt=Geom;;Point3d.new(rl*6, 0, 0)
vt=Geom;;Vector3d.new(0, gl, 0)
an=45.degrees
tr=Geom;;Transformation.rotation(pt,vt,-an)
mygroup1.transform!(tr)
UI.messagebox("mygroup1 rotated along Green axis. What's next?") # User Message to see what happened!
# Scale (mygroup2) uniform about origin x3
tr=Geom;;Transformation.scaling(3)
mygroup2.transform!(tr)
UI.messagebox("mygroup2 scaled uniform from origin. What's next?") # User Message to see what happened!
# Scale (mygroup2) uniform about origin
tr=Geom;;Transformation.scaling(0.3)
mygroup2.transform!(tr)
UI.messagebox("mygroup2 scaled uniform from origin. What's next?") # User Message to see what happened!
# Scale (mygroup2) non-uniform about origin
tr=Geom;;Transformation.scaling(3, 2, 1.5)
mygroup2.transform!(tr)
UI.messagebox("mygroup2 scaled non-uniform from origin. The End! ;o\)") # User Message to see what happened!
# ---------- End Main Code ----------
puts("\n END \n..........")
# end of SJH_Groups_Add.rb
Attached is a pic of my moved, rotated and scaled Groups. Doesn't seem much but this morning that would have been a pic of a Bug Splat! Happy, happy!
[image: wfVi_20110430_Capture4-Rotate-Scale.JPG]