Python IsCylinder needs a tolerance added

The Rhinoscript method allows for a tolerance, and is effective at finding cylindrical surfaces. The Python method lacks the tolerance option, so the results are less effective.

HighlightCylinder.py (364 Bytes)

Cylinders.3dm (439.7 KB)

The small script posted above will illustrate the issue on the cylinders.3dm file attached.

Technically, the cylindrical surfaces ignored may not be true cylinders, but for practical purposes, they need to be able to be recognized as such.

FWIW these surfaces were imported from Solidworks.

Thanks,

Dan

@stevebaer This can be easily implemented I think. (also note typo in description)

In surface.py, find the definition of IsCylinder()

def IsCylinder(object_id):
    "Determines if a surface is a portion of a cone"
    surface = rhutil.coercesurface(object_id, True)
    return surface.IsCylinder()

Change it to:

def IsCylinder(object_id, tol=Rhino.RhinoMath.ZeroTolerance):
    """Determines if a surface is a portion of a cylinder"""
    surface = rhutil.coercesurface(object_id, True)
    return surface.IsCylinder(tol)

If you are brave, you can try to put in this change yourself and see if it works…

surface.py can be found here:

C:\Users\<user>\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript

Edit:
In thinking about this - considering that you have like a 100 seats of Rhino IIRC, you don’t want to be modifying the surface.py file 100 times. So instead of waiting for IsCylinder to be “enhanced”, you can just make yourself a custom function that does the same:

import rhinoscriptsyntax as rs
import Rhino
def IsCylinderTol(object_id, tol=Rhino.RhinoMath.ZeroTolerance):
    """Determines if a surface is a portion of a cylinder within tolerance"""
    surface = rs.coercesurface(object_id)
    if surface: return surface.IsCylinder(tol)

–Mitch

Hi Mitch,

I just added it as a function, tweaked it a bit, and it works well. Thanks.

I’m hesitant to alter the surface.py (or any others) only due to the fact that I need to distribute these scripts to over 100 seats. It might become a nightmare trying to make sure everyone gets everything they need if it isn’t either handled as a service release update, or is part of my 1 compiled command.

Adding it as a function seems the “cleanest” way to do it.

Dan

ha ha, seems like great minds think alike!!