Problem solved!!!
It's all about vectors. One of the arguments of the method that is resposable for creating the protrusions must be a vector or the order of the four given points of the rectangle must choosen in a way that the vector can be derived as the difference between the first two points of de rectangle.
` def findface(pt)
arr = Sketchup.active_model.entities.grep(Sketchup::Face)
arr.each {|f| return f if f.classify_point(pt) == Sketchup::Face::PointInside}
return nil
end
def body
ents = Sketchup.active_model.entities
ents.clear!
f = ents.add_face([0, 0, 0], [60, 0, 0], [60, 40, 0], [0, 40, 0])
f.pushpull(-30)
end
def protr(array, extrusion)
ents = Sketchup.active_model.entities
base = ents.add_face(array)
arcvector = array[1].vector_to(array[0])
basenormal = base.normal
depthvector = basenormal.cross(arcvector).reverse
width = array[1].distance(array[0])
depth = array[2].distance(array[1])
basenormal.length = extrusion - width/2
basecenter = Geom::Point3d.new
basecenter.x = (array[0].x + array[1].x)/2
basecenter.y = (array[0].y + array[1].y)/2
basecenter.z = (array[0].z + array[1].z)/2
center = basecenter + basenormal
base.pushpull(extrusion + 1)
ents.add_arc(center, arcvector, depthvector, width/2, 0, Math::PI)
basenormal.length = extrusion + 0.5
findface(basecenter + basenormal).pushpull(-depth)
ents.add_circle(center, depthvector, 1)
findface(center).pushpull(-depth)
end
def test
body
protr [[22.0, 8.0, 30.0], [22.0, 20.0, 30.0], [10.0, 20.0, 30.0], [10.0, 8.0, 30.0]], 14.0
protr [[35.0, 8.0, 30.0], [47.0, 8.0, 30.0], [47.0, 20.0, 30.0], [35.0, 20.0, 30.0]], 14.0
end`