Rhino 8 Mac Python trim extruded polysurface

Hello,

I am trying to trim an extruded polysurface in Python. I have tried various settings for TrimSurface and TrimBrep, but cannot get it to work. Using Trim in Rhino works as expected.

I want to lose the part of the RRoofSheet which is inside the RRoofSheetCutter object. I have also created a simple surface, but again it is not trimmed.

I think that the TrimBrep approach is the simplest, but that is probably because I cannot find how to define an Interval.

I have commented out the various permutations that I have tried. I know that some have guid / brep confusion, but I was trying anything that came to mind.

Version 8 (8.28.26013.10002, 2026-01-13)

Regards, Garry.

TrimBrep.3dm (6.1 MB)

TrimBrep.gh (3.6 KB)

Hello,

I have borrowed the Trim line from the TrimBrep function in https://github.com/mcneel/rhinoscriptsyntax/blob/rhino-8.x/Scripts/rhinoscript/surface.py#L3206 to replace the TrimBrep statement in my code.

breps = brepToTrim.Trim(brepCutter, tol)

In this case, the except condition is not activated, so it appears that the Trim statement operates normally. However, the object is not trimmed.

The observations are the same on Windows. I will keep looking, but clearly I am misunderstanding something.

Regards, Garry.

Hello,

I found some confusion between rc. and rs. in my code. I have updated all lines to rs. for hinoscriptyyntax, but the commands still fail, calling the except condition.

Regards, Garry.

I’ve taken a quick look and there are two issues.
First rc.TrimBrep(nextguid[0], guid, tol) should be rs.TrimBrep(nextguid[0], guid, tol) instead. TrimBrep is a function in rhinoscriptsyntax which you import as rs, not in the Rhino API, imported as rc.

Furthermore, nextguid is not a list, but a guid, and thus can’t be accessed at index 0:

Could not trim the Roof Sheet: 4d59ea28-71c9-459c-9bb3-e1402141be70 ('Guid' object is not subscriptable)

Summa sumarum, you should change the line to rs.TrimBrep(nextguid, guid, tol) and it should work!

I’ve also changed your try/except statement to this:

try:
    # your code ...
except Exception as e:  # catch the exception instead of simply ignoring it
    print(f"Could not trim the Roof Sheet: {nextguid} ({e})")

You obfuscate all potential exceptions that could be thrown in the try portion of your code.
I would get rid of the try/except statement, unless you know how to handle it.
Otherwise, you’ll make debugging much harder for yourself than it actually is.

Generally, try/except is used with raise not print:

try:
    # code
except Exception as e:
    raise(e)

And even this is frowned upon, since I’m using Exception which will catch all exceptions.
Ideally you should be more precise and differentiate between various distinct exceptions and how to handle them, when they are caught.

@diff-arch Thank you. Much appreciated, and working. I had noticed the rs. gremlin and noted it in post 3, but the [0] index went unnoticed. I had to move the cutter to cover the portion of the poly surface to be retained.

I will read more on the try / except protocols to improve my code.

I have included the corrected files for the benefit of subsequent readers.

Regards, Garry.

TrimBrep.3dm (6.1 MB)

TrimBrep.gh (3.6 KB)