Jump to content
mavencolby

Evaluate Expression String as Float

Recommended Posts

Good morning and Merry Christmas!

I need to evaluate a string path and get a parameter value from it.

So far I have this as a string parm: 

`chsop("../cam")`/aperture/

This evaluates correctly as:

/obj/rendercam/aperture/

However when I try to reference this as a ch() operation, it doesn't evaluate correctly. It reads 0. How can I drive a float parameter correctly?

 

To be clear, I don't want to directly reference the camera:

// NOT this
ch("../../rendercam/aperture")

I want the user to put the path of the camera in the otl and be able to derive the aperture from the string.

Thanks!

cw

 

Share this post


Link to post
Share on other sites

Okay so I've tried a little Python, this should work but I can't wrap my head around putting this into a parameter:

 

def pig():
	node = hou.node('/obj/Frustrum/')
	path = hou.evalParm(node.parm('cam').path())
	
	x = hou.node(path)
	aperture = x.parm('aperture')
	
	n = hou.evalParm(aperture.path())
	return n

pig()

I'm trying to set as "scalex" on a transform sop, and even when it's set to evaluate Python it returns 0. But the code works in the Python shell. What the heck is happening?

Share this post


Link to post
Share on other sites

Got it to work! It needed to "return pig()" at the end. The final Python code looked like this:

def pig():
	node = hou.node('/obj/Frustrum/')
	path = hou.evalParm(node.parm('cam').path())
	
	x = hou.node(path)
	aperture = x.parm('aperture')
	
	n = hou.evalParm(aperture.path())
	return n

# NOTE the "return" before calling the procedure "pig()"
return pig()

This is probably overkill for what I was trying to do, but hey.. got my feet wet in Python! Hope this helps someone else.

 

cw

Share this post


Link to post
Share on other sites
6 hours ago, anim said:

you can just do this


ch(chsop('cam') + '/aperture')

 

 

get_parm_from_cam.hip

Ah great! Thanks Tomas! I was so close to that, and began pulling my hair out trying to figure which syntax was correct. Thanks for the solution :)

 

cw

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×