Please, I would like to insert a .skp file which concerns the three-dimensional drawing of a knob.
I wonder if it’s possible to insert the knob with its X-axis perpendicular to the face,
thus avoiding the use of the method “trf_rotz = Geom::Transformation.rotation(pts_a_insknob, Z_AXIS, -90.degrees)”, that presupposes the value of the angle of rotation…
in this way, whatever the angle of the face on the xy plane, the knob would always be positioned correctly…
some help…
thank you
Joseph
depth = 50.cm
height = 15.cm
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [0, depth, 0]
pts[2] = [0, depth, height]
pts[3] = [0, 0, height]
# Add the face to the entities in the model
face_1 = entities.add_face(pts)
#
grp_1 = entities.add_group(face_1)
grp_1.name = 'grp1'
#
pts_a = []
pts_a[0] = [20.cm, 50.cm, 0]
pts_a[1] = pts_a[0].transform([depth, 0, 0])
pts_a[2] = pts_a[1].transform([0, 0, height])
pts_a[3] = pts_a[2].transform([-depth, 0, 0])
# Add the face to the entities in the model
face_2 = entities.add_face(pts_a)
#
grp_2 = entities.add_group(face_2)
grp_2.name = 'grp2'
# Knob insertion point "face_1"...name = 'grpknob'
pts_insknob = pts[0].transform([0, depth / 2, height / 2])
#
grp_knob = entities.add_group
grp_knob.name = 'grpknob'
#
transform_1 = Geom::Transformation.new(pts_insknob)
#
filepath_knob = File.join(File.dirname(__FILE__), 'Pom_1.skp')
defComp_knob1 = model.definitions
compDef1 = defComp_knob1.load(filepath_knob)
grp_knob.entities.add_instance(compDef1, transform_1)
#
# Knob insertion point "face_2"...name = 'grpknob'
pts_a_insknob = pts_a[0].transform([depth / 2, 0, height / 2])
#
grp_knob1 = entities.add_group
grp_knob1.name = 'grpknob1'
#
transform_2 = Geom::Transformation.new(pts_a_insknob)
#
defComp_knob2 = model.definitions
compDef2 = defComp_knob2.load(filepath_knob)
grp_knob1.entities.add_instance(compDef2, transform_2)
#
trf_rotz = Geom::Transformation.rotation(pts_a_insknob, Z_AXIS, -90.degrees)
grp_knob1.transform! trf_rotz