After some struggles, I came up with this script which "solves" it, however I the ruby console plus crashes about 20 seconds after running this script, I have yet to figure out how to trap that error, whatever it is
link to animated gif demonstration:
https://drive.google.com/file/d/16QQNpN4UhxjZRFghHKzPZY_zYuAYbiHz/view?usp=drive_link
Here is the revised script that at least does what I was trying to do.
The difference is that I used transform_entities instead of transform!
that seemed to have the desired effect on the resulting face so that I could extract it's vertices after the xform. An idea I got from here: https://forums.sketchup.com/t/move-a-group-api-ruby/130338/5
module RotateFaces
def self.get_face_from_entities(things)
face = nil
things.each do |thing|
if thing.is_a?(Sketchup;;Face)
face = thing
break
end
end
return face
end
def self.rotate_face(entz, face, axis_pt1, axis_pt2, angle)
axis = axis_pt1.vector_to(axis_pt2)
xform = Geom;;Transformation.rotation(axis_pt1, axis, angle)
entz.transform_entities(xform, face)
return face
end
def self.get_face_vertices(face)
verts = []
face.outer_loop.vertices.each{|v| verts << v.position}
return verts
end
def self.create_rotated_face(entz, pts, axis_pt1, axis_pt2, angle)
model = Sketchup.active_model
active_entities = model.active_entities
model.start_operation("create rotated face",true,false,true)
face = self.get_face_from_entities(entz)
face_xformed = self.rotate_face(entz, face, axis_pt1, axis_pt2, angle)
verts = self.get_face_vertices(face_xformed)
model.commit_operation
return [verts, face_xformed]
end
end
model = Sketchup.active_model
active_entities = model.active_entities
begin
things1 = []
group1 = active_entities.add_group
pts1 = [[10,10,0], [20,10,0], [20,10,10], [10,10,10]]
pt0, pt1, pt2, pt3 = pts1
g1_entities = group1.entities
face1 = g1_entities.add_face(pts1)
puts "face1; ", face1
puts "group1;", group1
group2 = group1.copy()
things2 = RotateFaces.create_rotated_face(group2.entities, pts1, pts1[0], pts1[3], -90.degrees)
puts "create_rotated_face returned; ", things2
pts2 = things2[0]
face2 = things2[1]
puts "group2;", group2
# (10", 10", 0")
# (10", 0", 0")
# (10", 0", 10")
# (10", 10", 10")
group3 = group2.copy()
things3 = RotateFaces.create_rotated_face(group3.entities, pts2, pts2[1], pts2[2], -90.degrees)
puts "create_rotated_face returned; ", things3
pts3 = things3[0]
fac3 = things3[1]
# (20", -0", 0")
# (10", 0", 0")
# (10", 0", 10")
# (20", -0", 10")
puts "group3;", group3
group4 = group3.copy()
things4 = RotateFaces.create_rotated_face(group4.entities, pts3, pts3[0], pts3[3], -90.degrees)
puts "create_rotated_face returned; ", things3
pts4 = things4[0]
fac4 = things4[1]
puts "group4;", group4
puts "made it this far"
rescue StandardError => e
puts "error last global outer try;", e
end