How to create a custom filter to limit surface selection to specific solids

When using a custom getObject class to select surfaces I would like to be able to restrict the available choice to the faces of polysurfaces or extrusions that are on a predefined list.

It may be that I can’t see the wood for the trees but I can’t work out how to write a custom geometry filter to achieve that. Can anyone help?

Jeremy

– Dale

Hi Dale,

Thanks for your reply. I’m ok with the general mechanism for custom geometry filters (e.g. I have one that restricts selections to closed solids) but the aspect I am struggling with is how to limit surfaces that can be picked to those that are components of objects in a list. Specifically, I guess, how to reference the object that a surface is a component of.

Regards
Jeremy

Hi @jeremy5,

How about sometthing like this:

import Rhino
import rhinoscriptsyntax as rs

class GetMyObjects(Rhino.Input.Custom.GetObject):
    
    def __init__(self, object_ids):
        self.object_ids = object_ids
        
    # GetObject.CustomGeometryFilter override
    def CustomGeometryFilter(self, rh_object, geometry, component_index):
        if rh_object and rh_object.Id in self.object_ids:
            return True
        return False
     
def Test():
    
    object_ids = rs.GetObjects("Select objects")
    if not object_ids: return
    
    go = GetMyObjects(object_ids)
    go.SetCommandPrompt("Select specific objects")
    go.EnablePreSelect = False
    go.GetMultiple(1, 0)
    if go.CommandResult() != Rhino.Commands.Result.Success:
        return
        
    for i in range(0, go.ObjectCount):
        rh_obj = go.Object(i).Object()
        if rh_obj: print rh_obj.Id

Test()

– Dale

1 Like

Thanks Dale. I just added a standard geometry filter to the myObjects init to restrict the choice to Surfaces and I had exactly what I needed.

So the Id attribute of a component object is actually the Id of the object it is a component of… Definitely a case of wood and trees.

In gratitude,
Jeremy