How to "3d-crop" a complex model with ruby

There are some extensions which can cut the model, e.g.:

s4u Slice | SketchUp Extension Warehouse

s4u MultiSlice | SketchUp Extension Warehouse

Eneroth Slicer | SketchUp Extension Warehouse

Zorro2 | SketchUp Extension Warehouse

SectionCutFace | SketchUcation

These are not exactly what you want, but perhaps the s4u MultiSlice is the “closest”…

The Zorro2 is not encrypted, so perhaps you can examine that.

How easy it is to use them programmatically, is relative, once you’ve learned it, it can be easy, but you definitely have to put in the relevant effort to do it.
For example, you must know the definition of “solid” then you can use the boolean operation in combination with Entities #intersect_with-instance_method. But I’m afraid you can’t avoid further iteration of object to achieve your desired result…

It would be best if there were methods, for example, something like:
model.crop_copy( boundingbox ) >> result a group containing the copy of entities of that part of the model which is inside the bounding box
or
model.crop_cut( boundingbox ) >> result a group containing the copy of entities of that part of the model which is inside the bounding box, and a model without this new group…

But unfortunately there is no such >> you have to write it.