Hello
I make the frame in miter section of a surface in a component.
I made an offset of the surface with the call of the TIG plugin
I make a loop and I get the 4 points to create the face in a subcomponent then, I extrude it according to the desired thickness.
But I would like the x axis of these subcomponents to match the outer edge so that the textures can be applied correctly.
In a component, I therefore have the local coordinates of 4 coplanar points.
I want to create a sub component with a face since, it’s 4 points. I want the origin to be the 1st point and the x axis of the new component to be the line going through points 1 and 2 and the z axis to be that of the parent component.
Reading various answers on the forum, it would seem that once the definition has been created, add the face according to the 4 transformed points so that they correspond to the desired axes then place an instance of this new sub-component according to a transformation for position it correctly.
How to get the correct transformation of points and how to get the transformation to place the instance?
thanks in advance
Here is my code as it is
require 'TIG-Smart_offset.rb'
model = Sketchup.active_model
sel = model.selection
compo = sel.grep(Sketchup::ComponentInstance)[0]
model.start_operation("terrasse",true,false,false)
compo_def = compo.definition
compo_ents = compo.definition.entities
compo_face = compo_ents.grep(Sketchup::Face)[0]
#Offset
offset = 145.mm
fi = TIG::Smart_offset.new(compo_face, -offset)
#faces
compo_faces = compo_ents.grep(Sketchup::Face)
if compo_faces[0] == fi
fo = compo_faces[1]
else
fo = compo_faces[0]
end
#loops
lo = fo.outer_loop
if lo= fo.loops[0]
li= fo.loops[1]
else
li = fo.loops[0]
end
#edges
eo = lo.edges
ei = li.edges
#initialisation while for each edges of loop
en = eo.length
i = 0
while i < en
#match outer and inner edges
if i>0
j=(en-1)-(i-1)
else
j=i
end
#points to define face in sub_component
points = []
points[0] = eo[i].vertices[0].position
points[1] = eo[i].vertices[1].position
points[2] = ei[j].vertices[0].position
points[3] = ei[j].vertices[1].position
#Sub_component
lame_c = compo_ents.add_group.to_component
lame_c_ents = lame_c.definition.entities
lame_c_face = lame_c_ents.add_face(points)
lame_c_face.reverse!
lame_c_face.pushpull(21.mm,true)
lame_c_face.reverse!
lame_c.name='lame_cadre'+i.to_s
layer = Sketchup.active_model.layers.add "terrasse_lame_cadre"
lame_c.layer =layer
i= i+1
end #end of while
#cleaning edges offset
ei.each{|e|e.erase!}
model.commit_operation
Hello TomTom
Here are 3 screenshots, corresponding to the initial state before code, once the code is applied and what I would like the code to achieve.
thanks in advance
Thank you Dezmo, it is a beginning of reflection.
The idea in the end is to be able to apply the textures correctly and easily get the dimensions.
The truth is hidden in the transformations, but I’m not yet comfortable with it! I need to get the angle between the outer edge and the x-axis of the parent component and the translation between the point that will serve as the origin and the origin of the component, so these are its local coordinates. Then apply these transformations for each point. Create the component add the face according to these 4 new points, extrude then place the instance according to the inverse transformation. it’s easy in French much less in ruby.