What’s an efficient way to create a frame shape using the Ruby API? I don’t mean a door/window frame specifically just a basic frame that looks something like this.
I was wondering if anyone had any ideas on how to improve/simplify the code I’ve written as I see a number of minor issues.
Here’s what I got.
horz = X_AXIS.clone horz.length = 10 vert = Z_AXIS.clone vert.length = 10 outer_pts =  outer_pts << ORIGIN outer_pts << ORIGIN + horz outer_pts << ORIGIN + horz + vert outer_pts << ORIGIN + vert frame_horz = horz.clone frame_horz.length = 2 frame_vert = vert.clone frame_vert.length = 2 inner_pts =  inner_pts << ORIGIN + frame_horz + frame_vert inner_pts << ORIGIN + horz - frame_horz + frame_vert inner_pts << ORIGIN + horz - frame_horz + vert - frame_vert inner_pts << ORIGIN + frame_horz + vert - frame_vert ent = Sketchup.active_model.entities ent.add_face(outer_pts) ent.add_face(inner_pts).erase!
If I were to add this code into a function I’d also maybe need to add some sort of validation to ensure that both a negative and a positive frame lengths weren’t chosen to avoid intersecting the inner face with the outer face but also allow for cases in which 2 negative frame lengths were used. Once I added that my code would be fairly long for the simple task I’m trying to achieve. Maybe this highlights a larger problem in my methodology or perhaps I’m simply expecting too much from too little code.
Another idea I had was creating the face using edges and calling find_faces
This is purely curiosity by the way and is not a pressing issue.