Measure Nurb Curve Length in Python [SOLVED]

   4952   5   3
User Avatar
Member
183 posts
Joined: Dec. 2011
Offline
So I feel like I am probably overlooking something, but for the longest time I have been trying to find a way to calculate the length of a NURBs curve using python. Any ideas?
Edited by - Jan. 6, 2015 12:11:12
User Avatar
Member
617 posts
Joined: Aug. 2008
Offline
hscript and then you can run the arclen command.

or you can make a spare parameter, put the expression of the arclen in there.
and then
with python read that parameter and then eval.
User Avatar
Member
183 posts
Joined: Dec. 2011
Offline
I like the hscript idea. Is there a way to run a block of hscript in a python function?
User Avatar
Member
1799 posts
Joined: Oct. 2010
Offline
check out the hou.hscript() python function:

https://www.sidefx.com/docs/houdini13.0/hom/hou/hscript [sidefx.com]

I use it quite a bit for things that are “not” in python yet.

if your curve is a single primitive, you can also use a measure SOP to measure the perimeter and store it in a prim attribute, or if it is multiple primitives, use measure, then an attribute promote SOP, and promote perimeter to detail set to sum
-G
User Avatar
Member
183 posts
Joined: Dec. 2011
Offline
Excellent. I was originally considering having the shelf tool I'm making throw down a temporary measure sop before evaluating the curves, but that seemed a little hacky to me. hou.hscript seems like the solution.

One last question though, how do you pass in python variables to the hscript?
User Avatar
Member
183 posts
Joined: Dec. 2011
Offline
I have it figured out now. Turns out you need to use hou.hscriptExpression() with arclen() and can use string formatting to pass in python variables. Here is the test code that worked for me.

nodePath = “/obj/geo1/line1”
primNum = 0

myExpression = ‘arclen(“{0}”,{1},0,1)’.format(nodePath,primNum)

print hou.hscriptExpression(myExpression)

Thanks for your help guys!
  • Quick Links