algorithmic modeling for Rhino
Hi,
I searched the forum but couldn't find this exact issue...
I'm trying to use the following code to export a list based on the curve type that gets input. Basically, the original input is a polyline that is arcs and lines which is then exploded and I want to output a different value based on whether or not the input segment is an arc or a line. Any help would be much appreciated!
import rhinoscriptsyntax as rs
import Rhino as ri = x
print (x)
if i == r.Geometry.ArcCurve:
print ("Arc!")
a = "Arc"
elif i == r.Geometry.LineCurve:
print ("Line!")
a = "Line"
elif i == r.Geometry.Curve:
print ("Curve!")
a = "Curve"
else:
a = "Unsupported curve type!"
pass
Tags:
Sorry, to clarify, so far the code doesn't work and simply gives me the "Unsupported curve type!" output, which means it's not picking up on the Curve types above. The input is from an Explode component which gives a list of 'Arc-like Curve' and 'Line-like Curve' objects.
Got it!
Using rs.IsArc(x) and rs.IsCurveLinear(x) does the trick.
You could also use Python type checking like so:
if type(x) == Rhino.Geometry.NurbsCurve:
print "You've got a curve!"
This way you have a consistent type checking method for conditionals etc. I find this increases readability plus you immediately know which RhinoCommon object is being checked for. Hope that helps..
Edit: Note that type() will only check for that one specific type. If you need to take inheritance into account you can check like so:
if isinstance(x,Rhino.Geometry.NurbsCurve):
print "You've got a curve!"
Thanks, Anders! Handy.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by