Rhino 7 Python | Boolean difference of boxes

Hi, I have a building with a parapet enclosed by a larger box

All elements are boxes. How can I first do the Boolean difference of the building and the parapet. Then do the Boolean difference of the building with parapet and enclosure. The following code is written in Rhino Python Editor. Code is added as an attachment!
addboxes.py (1.3 KB)

You can do it like this:

import rhinoscriptsyntax as rs
from math import *

l = 40 # building length in m
w = 30 # building width in m
pH = 0.4 # parapet height in m
pW = 0.3 # parapet width in m
h = 10 + pH # roof height in m

#Addbox building
p1 = (-l/2,-w/2,0)
p2 = (l/2, -w/2,0)
p3 = (l/2, w/2,0)
p4 = (-l/2, w/2,0)
p5 = (-l/2,-w/2,h)
p6 = (l/2, -w/2,h)
p7 = (l/2, w/2,h)
p8 = (-l/2, w/2,h)

building = rs.AddBox([p1,p2,p3,p4,p5,p6,p7,p8])

#Addbox parapet
pp1 = (-l/2 + pW/2,-w/2 + pW/2,h)
pp2 = (l/2 - pW/2, -w/2 + pW/2,h)
pp3 = (l/2 - pW/2, w/2 - pW/2,h)
pp4 = (-l/2 + pW/2, w/2 - pW/2,h)
pp5 = (-l/2 + pW/2,-w/2 + pW/2,h-pH)
pp6 = (l/2 - pW/2, -w/2 + pW/2,h-pH)
pp7 = (l/2 - pW/2, w/2 - pW/2,h-pH)
pp8 = (-l/2 + pW/2, w/2 - pW/2,h-pH)

parapet = rs.AddBox([pp1,pp2,pp3,pp4,pp5,pp6,pp7,pp8])

#Addbox enclosure

pe1 = (-l/2 - 5*h, -w/2 - 5*h,0)
pe2 = (l/2 + 10*h, -w/2 - 5*h,0)
pe3 = (l/2 + 10*h, w/2 + 5*h,0)
pe4 = (-l/2 - 5*h, w/2 + 5*h,0)
pe5 = (-l/2 - 5*h, -w/2 - 5*h,6*h)
pe6 = (l/2 + 10*h, -w/2 - 5*h,6*h)
pe7 = (l/2 + 10*h, w/2 + 5*h,6*h)
pe8 = (-l/2 - 5*h, w/2 + 5*h,6*h)

enclosure = rs.AddBox([pe1,pe2,pe3,pe4,pe5,pe6,pe7,pe8])

# b = rs.GetObject("building")
# enc =  rs.GetObject("enclosure")
# par =rs.GetObject("parapet")

bool_1 = rs.BooleanDifference(building, parapet)
bool_2 = rs.BooleanDifference(enclosure, bool_1)

Thank you, this worked!

When I try to save the geometry via the script, a dialog box pops up, but it doesn’t save it when I press save. How can I clear the geometry between each run and save it automatically?

I tried to use:

rs.SaveFileName(“Save file”,None,“C:\Users\john\Desktop\R_geo_script”, “Rhino_cuboid_parapet_L= %gx_W= %gx_H= %g_p=%gx%g " % (l,w,h),”.x_t")

Is “C:\Users\john\Desktop\R_geo_script” a valid directory path?

Also try to change “Rhino_cuboid_parapet_L= %gx_W= %gx_H= %g_p=%gx%g " % (l,w,h) to "Rhino_cuboid_parapet_L={}_W={}_H={}_p={}".format(l, w, h)

Thanks for the response
Yes, it is a valid directory path

I changed the filename string to what you wrote. I see that “save as type” field is empty and not possible to edit. I can press save but there is no file there when I look inside Windows explorer.

Screenshot is in the attachment