Jump to content

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

 

Link to comment
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?

Link to comment
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...