Use name filter to limit allowable selection

Is there a way to limit object selection by a name filter in rhinoscript or rhinocommon for a Python function?

I have a set of objects with the following name format 0.vertex.0, 0.vertex.1, 1.vertex.1, 1.vertex.2, which I can see when I call rs.ObjectName(objectid). I’d like to have a wildcard filter such that only objects with 0.* can be selected (a custom filter by name).

Rhinoscript allows this for standard object geometries, i.e. the following script:

objectids = rs.GetObjects("Pick some objects", rs.filter.curve)

will not allow me to even select points.

However, I haven’t found a good example of a custom filter for rs.GetObjects.

I’d like to define a custom filter as follows:

def name_filter(RhinoObject, name): obj_name = rs.ObjectName(RhinoObject) if name == obj_name: return True return false

name = '0.Vertex.0' objectids = rs.GetObjects('Select vertices', custom_filter=name_filter(name))

Apologies for the formatting, I don’t know how to create proper indented blocks.

Does the custom_filter have to have three arguments (and only 3), as indicated in the documentation (rhino_object, geometry, component_index)? Is it possible to also pass the name wildcard to the custom_filter function?

The few examples I’ve found using custom filters also did not work as scripts for me (, where I still received an objectid for points despite a custom_filter existing for closed polylines.

@MClare, yes, below is an example which limits selection to objects having their object name start with “0.”

import rhinoscriptsyntax as rs
def DoSomething():
    # limit selection to points with a custom name filter
    ids = rs.GetObjects("Select", 1, False, False, False, custom_filter=my_filter)
    if not ids: return
    for id in ids:
        print rs.ObjectName(id)
def my_filter(rhino_object, geometry, component_index):
    # only allow objects with a name starting with "0."
    if rhino_object.Attributes.Name.startswith("0."):
        return True
    return False
if __name__=="__main__":

I think yes. It is based on the CustomGeometryFilter method which has 3 parameters. You can however use as many global variables in your custom_filter function as you like and define them before using rs.GetObjects in your main routine.

Just format your python code like this:

print "hello world"


Worked perfectly! Thanks.