I want to make a pointer inside a group or component selected. This group is a triangle and I want to place it on (bounds.center_x, bounds.center_y and bounds.max_z). I have earned to place the triangle into the group but I’m not able to place it in the desired point. I know that it’s something related to transformation but I don’t find anything I’m able to understad.
Can anyone help me?
This is the code
def pointer ()
model = Sketchup.active_model
entities = model.active_entities
sel = model.selection
sel.each do |ent|
grupos = ent.definition.entities.select { |e| e.is_a?(Sketchup::Group) && e.name == "_data" }
componentes = ent.definition.entities.select { |e| e.is_a?(Sketchup::ComponentInstance) && e.name == "_data" }
# group already exists
if grupos.length > 0 || componentes.length > 0
puts "group already exists"
else
d = ent.bounds.center
e = ent.bounds.corner(4)[2]
x = d[0]/39.3701
y = d[1]/39.3701
pts = []
pts[0] = [x-1,y,e]
pts[1] = [x+1,y,e]
pts[2] = [x,y,e+2]
# Add a group to the model.
group = entities.add_group
cc = group.entities.add_face(pts)
connected = cc.all_connected
#insert group into group
seltrans = ent.transformation
seldef = group.definition
if ent.is_a? Sketchup::Group
selinstance = ent.entities.add_instance seldef, seltrans
elsif ent.is_a? Sketchup::ComponentInstance
selinstance = ent.definition.entities.add_instance seldef, seltrans
end
selinstance.name = "_data"
group.erase!
end
end
end
pointer()
Internally, all lengths in SketchUp are stored in inches.
You are “manually” converting inches to meters in x,y coordinates, then you subtract/add inches from it…while the z coordinate, still in inch… this makes no sense for me…
Yes, it seems ridiculous but I don’t know why it worked at that moment. There is a difference between x and e, it seems that d[0] units are differect than ent.bounds.corner(4)[2].
By the way my problem is not the dimensions (I will solve later) but the placement of the gruops I’m creanting that they are not at the desired place inside the parent group or component.