Finding objects hidden by clipping plane in viewport

I have a script which adds text on the objects visible in a detail. The script includes a method which determines which objects are visible in the detail. This works great except with clipping planes. Any objects hidden by a clipping plane get the text, which they should not. Does anyone know how to determine which objects in a detail are hidden by a clipping plane?

Here is the method:

def _is_object_in_viewport(obj, viewport, clippingPlanes):
    """
    Check if an object is visible in the viewport.
    """    
    layer_for_obj = sc.doc.Layers[obj.Attributes.LayerIndex]
    if not layer_for_obj.PerViewportIsVisible(viewport.Id):
        return False
    if obj.Attributes.HasHideInDetailOverrideSet(viewport.Id):
        return False    
    bbox = rs.BoundingBox(obj)        
    does_contain = True
    for p in bbox:
        does_contain = viewport.GetFrustumBoundingBox().Contains(p)
        if not does_contain:
            break
    return does_contain

Hi @GaryC, below is a quick script and example file:

GaryC_ClippingPlaneTest.3dm (297.3 KB)
GaryC_ClippingPlaneTest.py (1.7 KB)

The file contains 3 named objects, a sphere a small and a large box. The sphere is outside the detail, the small and large box are both visible in the detail. The large box is partially clipped, the small box is fully ‘behind’ the clipping plane…so i asume it is clipped in the detail…

Does that help ?

_
c.

1 Like

@clement, that’s perfect. Thanks very much. I did get a different version working, but it only worked with one clipping plane and had another 40-50 lines of complicated code! Your version is far more elegant! Thanks again.