Special analyze over entities

hi there, we have some group that represent a set of cabinets as draft, also a dynamic component that will replace over each (top face) of that group.

at the first we should make a code that take top face of group to know partition :

sele = Sketchup.active_model.selection
z_face = sele.first.entities.grep(Sketchup::Face).find_all{|x| x if (x.normal == Z_AXIS) && x.edges.length<8}

now how to replace this component over facees ? tanks

I don’t think there are enough information to determine how the cabinets have to be oriented, where should be an insertion point of cabinet… we do not know how this cabinets are constructed, where its axes and origin located…etc.etc… therefore we could not define the transformation necessary to place that component.

Some notes and ideas:

The z_face in your code actually, is an array of faces, I would call it z_faces.
BTW The find_all (and its alias select) method returns an array containing all elements of enum for which the given block returns a true value. You do not need to use if statement there, this will do the same (also I changed x to more eloquent face)

....find_all{|face| face.normal == Z_AXIS && face.edges.length < 8}

I do not see your group bottom in the picture, but I assume there is (are) a face(s) laying on a ground plane, I guess that might be found by the above method too. You may need to check one of the face vertices position and select accordingly. (perhaps the orientation check - as you did - is enough…)

If you know the “Depth” of the cabinets, you can check the face edges length and at least determine two possible orientation of the cabinet, unfortunately if the face is a square you are in trouble…

The situation is further complicated by the fact that the rows of cabinets are likely to be “L” or “U” shaped. It’s really hard to figure out how and where the rows will turns…