It seems there is no easy way to orient faces of a solid with a single method within the API.
I’m working with non-orthogonal prismatic solids (6 faces, 12 edges) so nothing too complicated here.
Since I can’t push-pull this geometry into existence I first calculate my vertices (points) and then draw lines between them and finally use the find_faces method to created the faces.
Sometimes all of my faces are reversed and sometimes they are all oriented correctly.
Here is the code:
group1cut = Sketchup.active_model.active_entities.add_group
entities1cut = group1cut.entities
line1 = entities1cut.add_line p1,p2
line2 = entities1cut.add_line p2,p3
line3 = entities1cut.add_line p3,p4
line4 = entities1cut.add_line p4,p1
line1a = entities1cut.add_line p1a,p2a
line2a = entities1cut.add_line p2a,p3a
line3a = entities1cut.add_line p3a,p4a
line4a = entities1cut.add_line p4a,p1a
linea = entities1cut.add_line p1,p1a
lineb = entities1cut.add_line p2,p2a
linec = entities1cut.add_line p3,p3a
lined = entities1cut.add_line p4,p4a
line1.find_faces
linec.find_faces
line4a.find_faces
I’m wondering if anyone has come up with a good algorithm for checking to see if a solid has its faces oriented properly?
I’m thinking I can probably create my own algorithm for this sort of thing, here is my proposed recipe:
1.) Determine a point inside the solid (group or component)
2.) Use the project_to_plane method to cycle through all of the faces of the solid, calculate their planes and then use the projected point to calc the vector then compare this vector to the face normal vector and if they aren’t in the same direction, reverse the face.