Filtering for circles with Rhino.Input.Custom.GetObject()

I see GeometryFilter and GeometryAttributeFilter, but I don’t see any specific circle filter (like IsCircle would work)…

go = Rhino.Input.Custom.GetObject()
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve
# circle?

Thanks, --Mitch

Hi Mitch,

There is an example that does what you want, using Custom Filters http://wiki.mcneel.com/developer/rhinocommonsamples/customgeometryfilter.

Try this. This is rhinoscript, if I have time I will try and upload a version in Rhinocommon.

import rhinoscriptsyntax as rs
from scriptcontext import *
import Rhino
 
def circleGeometryFilter (rhObject, geometry, componentIndex):
    curve = rs.coercecurve(geometry)
    return rs.IsCircle(curve)
 
def RunCommand():
    objects = rs.GetObjects("Select Circles", rs.filter.curve, False, False,custom_filter = circleGeometryFilter)
    for curve in objects:
        point = rs.CircleCenterPoint(curve)
        rs.AddPoint(point)
    print len(objects)

if __name__=="__main__":
    RunCommand()

Regards,

Miguel

Yeah, thanks, I know how to do that with rhinoscriptsyntax… If you dive down into selection.py and look at the GetObject() method, it looks pretty complex in RhinoCommon… Again, as per some earlier posts, I’m looking to combine object selection with other options simultaneously instead of serially, hence RhinoCommon Custom.GetObject() and not rs.GetObject().

–Mitch

Edit: OK, I got it… It was actually as simple as using the same custom_filter you use for the rhinoscriptsyntax version and just calling it inside my go with SetCustomGeometryFilter():

def circ_filt(rhino_object, geometry, component_index):
    return geometry.IsCircle()

def GetCircleOrNumber(prompt):
    #prompt==command line prompt
    #returns None if Esc is pressed or no objects are chosen
    #otherwise, returns objectID or value
    
    go = Rhino.Input.Custom.GetObject()
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
    go.SetCustomGeometryFilter(circ_filt)
    go.SetCommandPrompt(prompt)
    go.AcceptNumber(True,False)
    #etc...
1 Like