First off, you can post correctly formatted code if you do the following:
Start with 3 “backticks” and the language name
Paste your code in
End with 3 more backticks
Like this:
Now as to your code, you are running into two things:
import rhinoscriptsyntax as rs
def crv_filt(rhino_object, geometry, component_index):
if rs.IsCurve(geometry): #you forgot this line
if rs.IsCurvePlanar(geometry):
if rs.IsCurveClosed(geometry):
return True
elif rs.IsSurface(geometry):
if rs.IsSurfacePlanar(geometry):
return True
return False
But, it still doesn’t work to exclude non-planar surfaces. I went and looked at my function for this and it is the following:
def cpcs_filt(rhino_object, geometry, component_index):
if rs.IsCurve(rhino_object.Id):
if rs.IsCurveClosed(rhino_object.Id):
if rs.IsCurvePlanar(rhino_object.Id):
return True
elif rs.IsSurface(rhino_object.Id):
if rs.IsSurfacePlanar(rhino_object.Id):
return True
return False
Which is actually identical in structure, but uses rhino_object.Id
to identify the object instead of geometry
. This one works to limit the selection to only closed planar curves and planar surfaces. It’s actually odd that my code is written like that, I seem to recall that I had the same question a long time back and someone suggested this as a workaround. It seems like the code using geometry
should also work…
Also, you can get a more compact code if you use some RhinoCommon notation instead:
def cpcs_filt(rhino_object, geometry, component_index):
if geometry.IsPlanar():
if isinstance(geometry, Rhino.Geometry.Curve):
if not geometry.IsClosed: return False
return True
return False
What works here is that both curve and surface objects have the RhinoCommon method IsPlanar()
, so afterwards you just have to check if the curve is closed.