Script to cut windows and doors into walls

 From:  Larry Fahnoe (FAHNOE)
10907.1 
I have an idea for a script that I’d appreciate a little advice or help on.

When I make a model of a building, I create the walls and then add the windows and doors. The walls may be either multiple surfaces with empty space between, or multiple layers of solids (representing the building materials). I draw the outlines of the windows on one side of the walls. Next I cut the windows through the walls leaving behind the framed opening (just simple surfaces). Since a model has many windows to cut out, and several steps are required for each window, a script would be helpful and save time.

Outline of steps for each window:
1. Select outline curve of window
2. Extrude (without capping ends) to wall thickness
3. Select layers of the wall
4. Boolean difference using the extrusion as the cutting object (keep objects)
5. If wall was composed of solids, delete each solid layer

One challenge is to determine the thickness of the wall so as to know how deep the cutting extrusion needs to be. An alternative might be to use a plausible oversized estimate of the wall thickness, but then an additional step would be needed to trim off the excess of the cutting object. I can visualize the script traversing the normal from one surface, collecting a list of intersecting objects to be cut, but I don’t yet see something in the API that might work, so this is an area I’m seeking advice. In the case of a wall composed of solids, after the boolean difference, the normal would again need to be traversed but this time intersecting objects would be deleted.

===================================
1/1/2023

After some tinkering with MoI's API here’s the script that I came up with to solve the problem I described above.

CutWalls is primarily intended for cutting windows and doors in the walls of architectural models. It can optionally create a solid frame and a surface to represent a pane of glass, either of which may be named.

Windows to be cut are expected to be represented by closed, planar curves located on one of the wall's surfaces. Because of MoI’s flexibility the script can be used on more than architectural models. Potential ideas might include different shapes of windows or curves set on on angle to the walls—though this gets a little bizarre.

Walls may be made up of surfaces and/or solids. The FindPts() function seeks to find the thickness of the wall by looking for selected wall (base) objects on either side of the window curve. Probe depth (which defaults to 15 inches) defines how far on either side. If a frame is to be made it will be extruded to this thickness. I was hoping to be able to have the script find the neighboring objects without having to “probe” for them like this, but haven’t figured out a way to do that. I appreciated Peer's suggestion though I wasn’t successful with the dropPoint method…something perhaps for a different script.

In a sense this is a specialized variation on the theme of MoI's Boolean Difference command which served as one of the examples that I used.

===================================
1/6/2023

Some improvements to the logic of finding the wall's thickness and positioning the glass, as well as not inadvertently deleting the names of solids. Also added Pilou's translation to French.

--Larry

EDITED: 8 Jan 2023 by FAHNOE