Python Script for Creating New CropBoxes not working

Hello all, Not sure why this python script is not working. The functionality of the script only goes as far as creating a cropbox exactly around the rooms that I feed in, but I need it to create a cropbox with an offset of a few feet so that door swings and other things are visible. Keep in mind I am passing in non-rectangular room elements in. Whenever I try to put a value in the XYZ() function, like (1,1,0) for example, I get an error saying “Exception: Curve loop couldn’t be properly trimmed.”


Any ideas? The CreateViaOffset method is not working properly, and I am doing something wrong with regards to it, but I am not sure what.


you might get that error when you try to offset some really short curves that when offset (for example inwards) would actually disappear. try this on something really simple like a rectangular room first. Make sure that direction is correct. Also, the call to retrieve boundary segments returns a list of lists that contains the segments. Is it always true that first list in that collection is the one that contains the outer most boundaries of the room? (in case that room has multiple loops defining its boundary ex. doughnut) One last thing, I don’t think that you have to remove the crop region shape to reset it. As a matter of fact I would first try to just set it without removing it. Of course you haven’t gotten there yet, so let’s first try to figure out the Offset call.

also, a little bit of advice on Python itself. if your two lists: areas and views are of equal length you can access respective items in each by using zip() like so:

for area, view in zip(areas, views):

do something with area and respective view

This way, you can eliminate that funky counter.

Of course there are multiple ways to skin the cat. Another approach would be to use list length and range():

for i in range(0, len(area), 1):

area = areas[i]

view = views[i]

This method is a little bit more explicit but some people like it.

Hey Konrad,

Thanks for the advice as usual. I used your tips to trim my code a bit and make it slightly more organized, but with regards to the problem at hand, I am still stumped. I tested the script on a simple rectangular room, and nothing happened, and if I changed the XYZ position from the origin, it threw a “Couldn’t trim” error. I know none of the rooms I am working with have multiple boundary segments either, so I don’t think that is the problem. I’m amazed at how simple it is to create crop boxes that match the exact size of the room, but it is so difficult to create a crop box that is slightly off-set from the room. I don’t think the curves are small at all, mainly because the segments that form the crop box after the script runs are fairly large lines, and one room is only composed of 5-6 boundary segments at the most.

I have one method of generating offset boundaries using dynamo, but I can’t use that either because I have no idea how to format this script to allow for the input of my own curves. When I try to input my own curves into the script, I always get the error “expected curve, got curve.”