RhinoCommon API
CurveTryGetCircle Method (Circle) |
Try to convert this curve into a circle using RhinoMath.ZeroTolerance.
Namespace: Rhino.Geometry
Assembly: RhinoCommon (in RhinoCommon.dll)

public bool TryGetCircle( out Circle circle )
Public Function TryGetCircle ( <OutAttribute> ByRef circle As Circle ) As Boolean
Parameters
- circle
- Type: Rhino.GeometryCircle
On success, the Circle will be filled in.
Return Value
Type: Booleantrue if the curve could be converted into a Circle.

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; } } }
Imports Rhino Imports Rhino.Geometry Imports Rhino.Commands Imports Rhino.Input.Custom Imports Rhino.DocObjects Namespace examples_vb Public Class CustomGeometryFilterCommand Inherits Command Private _tolerance As Double Public Overrides ReadOnly Property EnglishName() As String Get Return "vbCustomGeometryFilter" End Get End Property Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result _tolerance = doc.ModelAbsoluteTolerance ' only use a custom geometry filter if no simpler filter does the job ' only curves Dim gc = New GetObject() gc.SetCommandPrompt("select curve") gc.GeometryFilter = ObjectType.Curve gc.DisablePreSelect() gc.SubObjectSelect = False gc.[Get]() If gc.CommandResult() <> Result.Success Then Return gc.CommandResult() End If If gc.[Object](0).Curve() Is Nothing Then Return Result.Failure End If Rhino.RhinoApp.WriteLine("curve was selected") ' only closed curves Dim 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 Then Return gcc.CommandResult() End If If gcc.[Object](0).Curve() Is Nothing Then Return Result.Failure End If Rhino.RhinoApp.WriteLine("closed curve was selected") ' only circles with a radius of 10 Dim gcc10 = New GetObject() gcc10.SetCommandPrompt("select circle with radius of 10") gc.GeometryFilter = ObjectType.Curve gcc10.SetCustomGeometryFilter(AddressOf CircleWithRadiusOf10GeometryFilter) ' custom geometry filter gcc10.DisablePreSelect() gcc10.SubObjectSelect = False gcc10.[Get]() If gcc10.CommandResult() <> Result.Success Then Return gcc10.CommandResult() End If If gcc10.[Object](0).Curve() Is Nothing Then Return Result.Failure End If Rhino.RhinoApp.WriteLine("circle with radius of 10 was selected") Return Result.Success End Function Private Function CircleWithRadiusOf10GeometryFilter(rhObject As Rhino.DocObjects.RhinoObject, geometry As GeometryBase, componentIndex As ComponentIndex) As Boolean Dim isCircleWithRadiusOf10 As Boolean = False Dim circle As Circle If TypeOf geometry Is Curve AndAlso TryCast(geometry, Curve).TryGetCircle(circle) Then isCircleWithRadiusOf10 = circle.Radius <= 10.0 + _tolerance AndAlso circle.Radius >= 10.0 - _tolerance End If Return isCircleWithRadiusOf10 End Function End Class End Namespace
Python
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()

Rhino for Mac
Supported in: 5.4Rhino for Windows
Supported in: 6.14