Rhino8 How to do Selective Clipping from a script

Is there a way to run the Selective Clipping added in Rhino 8 from a script?

I want to clip only specified objects.

image

The Clipping Plane Geometry has a SetClipParticipation and GetClipParticipation method along with a bool toggle ParticipationListsEnabled

Using these 3 together you can query a clipping plane for its list of objects/layers as well as set them and then toggle those lists active/inactive.

Here’s a simple example of their usage.

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

def pick_clipping_plane_and_filter_objects():
    # Prompt to pick a clipping plane
    go = Rhino.Input.Custom.GetObject()
    go.GeometryFilter = Rhino.DocObjects.ObjectType.ClipPlane
    go.SetCommandPrompt("Select clipping plane")
    go.EnableUnselectObjectsOnExit(True)
    go.Get()

    if go.Result() != Rhino.Input.GetResult.Object:
        return 

    # Make sure we have a valid clipping plane object
    cp = go.Object(0).Object() 
    if cp is None or not isinstance(cp, Rhino.DocObjects.ClippingPlaneObject):
        return 

    # Pick some objects to exclude
    go.EnablePreSelect(False, True)
    go.SetCommandPrompt("Select objects to filter")
    go.GeometryFilter = Rhino.DocObjects.ObjectType.AnyObject
    go.GetMultiple(0, 0)
    
    if go.Result() != Rhino.Input.GetResult.Object:
        return

    # Grab the ids of the objects to exclude
    selected_object_ids = [o.ObjectId for o in go.Objects()]
    
    # Enable the clipping list
    cp.ClippingPlaneGeometry.ParticipationListsEnabled = True
    
    # Set any object ids or layer indices into the clip lists and toggle the IsExclusion bool
    cp.ClippingPlaneGeometry.SetClipParticipation(selected_object_ids, None, True)
    
    # Commit the changes
    cp.CommitChanges()

    # Query the clipping plane object for its existing list of objects and layers
    object_ids, layer_indices, is_exclusion_list = cp.ClippingPlaneGeometry.GetClipParticipation()

    print("object count: {}".format(len(object_ids)))
    print("layer count: {}".format(len(layer_indices)))
    print("is exclusion list {}".format(is_exclusion_list))

if __name__ == "__main__":
    pick_clipping_plane_and_filter_objects()


3 Likes

Thanks for the response!
It worked.
I was looking inside ClippingPlaneObject, but I see that there is a separate ClippingPlaneSurfaceClass!

Thank you.

1 Like