Click or drag to resize
GetObjectSetCustomGeometryFilter Method
Set filter callback function that will be called by the CustomGeometryFilter

Namespace: Rhino.Input.Custom
Assembly: RhinoCommon (in RhinoCommon.dll) Version: 5.1.50000.0 (5.0.20693.0)
Syntax
public void SetCustomGeometryFilter(
	GetObjectGeometryFilter filter
)

Parameters

filter
Type: Rhino.Input.CustomGetObjectGeometryFilter

[Missing <param name="filter"/> documentation for "M:Rhino.Input.Custom.GetObject.SetCustomGeometryFilter(Rhino.Input.Custom.GetObjectGeometryFilter)"]

Examples
using Rhino;
using Rhino.Geometry;
using Rhino.Commands;
using Rhino.Input.Custom;
using Rhino.DocObjects;

namespace examples_cs
{
  public class CustomGeometryFilterCommand : Command
  {
    private double m_tolerance;
    public override string EnglishName { get { return "csCustomGeometryFilter"; } }

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      m_tolerance = doc.ModelAbsoluteTolerance;

      // only use a custom geometry filter if no simpler filter does the job

      // only curves
      var gc = new GetObject();
      gc.SetCommandPrompt("select curve");
      gc.GeometryFilter = ObjectType.Curve;
      gc.DisablePreSelect();
      gc.SubObjectSelect = false;
      gc.Get();
      if (gc.CommandResult() != Result.Success)
        return gc.CommandResult();
      if (null == gc.Object(0).Curve())
        return Result.Failure;
      Rhino.RhinoApp.WriteLine("curve was selected");

      // only closed curves
      var gcc = new GetObject();
      gcc.SetCommandPrompt("select closed curve");
      gcc.GeometryFilter = ObjectType.Curve;
      gcc.GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve;
      gcc.DisablePreSelect();
      gcc.SubObjectSelect = false;
      gcc.Get();
      if (gcc.CommandResult() != Result.Success)
        return gcc.CommandResult();
      if (null == gcc.Object(0).Curve())
        return Result.Failure;
      Rhino.RhinoApp.WriteLine("closed curve was selected");

      // only circles with a radius of 10
      var gcc10 = new GetObject();
      gcc10.SetCommandPrompt("select circle with radius of 10");
      gc.GeometryFilter = ObjectType.Curve;
      gcc10.SetCustomGeometryFilter(CircleWithRadiusOf10GeometryFilter); // custom geometry filter
      gcc10.DisablePreSelect();
      gcc10.SubObjectSelect = false;
      gcc10.Get();
      if (gcc10.CommandResult() != Result.Success)
        return gcc10.CommandResult();
      if (null == gcc10.Object(0).Curve())
        return Result.Failure;
      RhinoApp.WriteLine("circle with radius of 10 was selected");

      return Result.Success;
    }

    private bool CircleWithRadiusOf10GeometryFilter (Rhino.DocObjects.RhinoObject rhObject, GeometryBase geometry,
      ComponentIndex componentIndex)
    {
      bool is_circle_with_radius_of10 = false;
      Circle circle;
      if (geometry is Curve && (geometry as Curve).TryGetCircle(out circle))
        is_circle_with_radius_of10 = circle.Radius <= 10.0 + m_tolerance && circle.Radius >= 10.0 - m_tolerance;
      return is_circle_with_radius_of10;
    }
  }
}
import rhinoscriptsyntax as rs
from scriptcontext import *
import Rhino

def circleWithRadiusOf10GeometryFilter (rhObject, geometry, componentIndex):
  isCircleWithRadiusOf10 = False
  c = rs.coercecurve(geometry)
  if c:
    b, circle = c.TryGetCircle()
  if b:
    isCircleWithRadiusOf10 = circle.Radius <= 10.0 + Rhino.RhinoMath.ZeroTolerance and circle.Radius >= 10.0 - Rhino.RhinoMath.ZeroTolerance
  return isCircleWithRadiusOf10

def RunCommand():
  # only use a custom geometry filter if no simpler filter does the job

  # for curves - only a simple filter is needed
  if rs.GetObject("select curve", rs.filter.curve): #Rhino.DocObjects.ObjectType.Curve):
    print "curve vas selected"

  # for circles with a radius of 10 - a custom geometry filter is needed
  if rs.GetObject("select circle with radius of 10", rs.filter.curve, False, False, circleWithRadiusOf10GeometryFilter):
      print "circle with radius of 10 was selected"

if __name__=="__main__":
  RunCommand()
See Also