Change axes of Group


hai everyone, can i change the axes of group via ruby by specific face ??

Changing the axis of a group/component is possible applying a transformations. You need to transform its definition content, then the instance(s) with the inverse transform. There are many topic about this in this forum. Search for it.

One example:

i have try modif your code, but that is not work.

def create_group_and_transform_study
	model = Sketchup.active_model
	enta = model.active_entities
	sel = model.selection
	group1 = sel[0]
	faces = group1.entities.grep(Sketchup::Face)
	face1 = nil
	faces.each{|e| 
	y =e.normal.y
	if y==-1
		e.material="red"
		face1 = e
	end
	
}
  
  #group1 = enta.add_group
  #Just to see the bundig box:
  #Sketchup.active_model.selection.add group1
  
  UI.messagebox("Empty group1 created in model origin")
  
  # Create points in model cord. system
  #p1m = Geom::Point3d.new(0, 1, 1)
  #p2m = Geom::Point3d.new(1, 0, 1)
  #p3m = Geom::Point3d.new(1, 2, 2)
  #face1 = group1.entities.add_face( p1m, p2m, p3m )
  
  # Get the group1 current transformation
  tr_group1 = group1.transformation
  # and see the coordinates in group1 cord. system
  vert0_posm1 = face1.vertices[0].position
  puts "Vertices 0 group1 cord 1st: #{vert0_posm1.to_a}"
  puts "Face normal group1 cord 1st: #{face1.normal.to_a}"
  # and see the coordinates in model cord. system
  vert0_posg1 = face1.vertices[0].position.transform(tr_group1)
  puts "Vertices 0 model cord 1st: #{vert0_posg1.to_a}"
  puts "Face normal model cord 1st: #{face1.normal.transform(tr_group1).to_a}"
  puts
  UI.messagebox("Face created in group1.")
  
  # I want the group1 axes origin on one of the face vertices
  group_opoint = vert0_posm1
  # I want the group1 Z axis parallel to face1 normal
  group_z_axis = face1.normal
  # Creates a Transformation where origin is the new origin, and zaxis is the z axis.
  tr_orig_zax = Geom::Transformation.new(group_opoint, group_z_axis)
  
  # Transform the group1 INSTANCE with this transformation
  group1.transform!( tr_orig_zax )
  
  # Get the group1 current transformation 2nd stage
  tr_group2 = group1.transformation
  # and see the coordinates in group1 cord. system
  vert0_posm2 = face1.vertices[0].position
  puts "Vertices 0 group1 cord 2st: #{vert0_posm2.to_a}"
  puts "Face normal group1 cord 2st: #{face1.normal.to_a}"
  # and see the coordinates in model cord. system
  vert0_posg2 = face1.vertices[0].position.transform(tr_group2)
  puts "Vertices 0 model cord 2st: #{vert0_posg2.to_a}"
  puts "Face normal model cord 2st: #{face1.normal.transform(tr_group2).to_a}"
  puts
  UI.messagebox("group1 INSTANCE transformed by origin/axes")
  
  # Transform the group1 DEFINICION ENTITIES back with 
  # this transformation inverse
  myentities = group1.definition.entities
  myentities.transform_entities(tr_orig_zax.inverse, myentities.to_a)
  
  # Get the group1 current transformation 3rd stage
  tr_group3 = group1.transformation
  # and see the coordinates in group1 cord. system
  vert0_posm3 = face1.vertices[0].position
  puts "Vertices 0 group1 cord 3rd: #{vert0_posm3.to_a}"
  puts "Face normal group1 cord 3rd: #{face1.normal.to_a}"
  # and see the coordinates in model cord. system
  vert0_posg3 = face1.vertices[0].position.transform(tr_group3)
  puts "Vertices 0 model cord 3rd: #{vert0_posg3.to_a}"
  puts "Face normal model cord 3rd: #{face1.normal.transform(tr_group3).to_a}"
  puts
  UI.messagebox("group1 DEFINICION ENTITIES transformed 'back' by origin/axes")
  return "Do you see?"
end
create_group_and_transform_study