Python - Get Curve Degree

Hello,

I’m trying to create simple ghpython component that returns the degree number value of the input curve list and stuck on how my input should be hinted/called.

It appears it wants a guid or a string as the input but I want to be able to feed it referenced curves inside GH so I don’t always have guids available for all inputs.

Thanks for your help and pointing me in the right direction!

Script thus far:

import rhinoscriptsyntax as rs
import scriptcontext as sc

if rs.IsCurve(C):
    degree = rs.CurveDegree(C)
    print "Curve degree:", degree

D = degree

Graph space:

Hello @michaelvollrath ,

your problem can probably be solved by right-clicking the C input in your python component and setting it’s type hint to Curve.

See the documentation of the ghpython component for reference, which is admittedly a bit convoluted in it’s wording:

The rhinoscriptsyntax Type Hint is special: when it is selected, any geometry will be added to the Grasshopper document, and then its ID (Guid) inside it will be passed in the variable. With the rest of the hints, GhPython will call into Grasshopper and perform the same type of operations that Grasshopper does when it requires a special data type. This conversion is costly. If you want to make things as quick as possible, choose ‘No Type Hint’. However, users of your component will benefit greatly from using a meaningfully-set and appropriate type hint.

I did try that without success and then realized I had values in my input list, when I used the clean tree component it now works as expected.

Thanks for your help @lando.schumpich , any tips for the script to ignore null values if I don’t want to add the clean tree component in front of the input?

I thought the first line if statement would handle this (if rs.IsCurve) but I guess not…

I would like to carry the null values onward if possible as sometimes it makes it easier downstream with matching certain data tree operations.

True, the component does not love being fed null data. A simple way to filter null items in python, while still including your condition could look like this:

# Check if C is none and just pass it along if that's the case
if C is None:
    D = C
else if rs.IsCurve(C):
    # Your custom logic goes here
1 Like

Thanks Lando, this makes sense. I’ll test and get back to you. Appreciate the help!

Here’s what I ended up with that works:

import rhinoscriptsyntax as rs

if C is None:
    D = C
elif rs.IsCurve(C):
    degree = rs.CurveDegree(C)
    print "Curve degree:", degree

    D = degree

Thanks for your help!

1 Like