python expressions in parameters

   5981   8   1
User Avatar
Member
221 posts
Joined: July 2005
Offline
I'm just starting to learn python, so I'm sure that this is quite the newbie question.

What magic combination of switches and settings do I need to set so that I can put a python expression in a parameter field and have it evaluate?

I know that I can put `pythonexprs(“hou.blah.blah()”)` in an expression, but that seems like it's more work than it's worth. I can't seem to put `hou.blah.blah()` in and have it work.

And yes, I know that hou.blah.blah() is not a real python function. :roll:

Dave
User Avatar
Member
85 posts
Joined: July 2005
Offline
Maybe you ve done it already, but did you change from Hscript to Python on the top right of the parameter box?
User Avatar
Member
345 posts
Joined:
Offline
Hi Dave,

You need to import hou module first.
Here is a quick example what you can do with it…
http://forums.odforce.net/index.php?showtopic=7103&hl= [forums.odforce.net]

hope it helps.

kuba
User Avatar
Member
1909 posts
Joined: Nov. 2006
Offline
When using Python in parameters, really the only thing required is that the node or parameter have it's language set to Python. You actually don't need to import hou. Parameters automatically do a ‘from hou import *’ This is why you can do a ‘ch()’ in them while set to python and it works alright. The only slightly tricky thing is python in a string parameter.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
221 posts
Joined: July 2005
Offline
Ok, so how do I do the “slightly tricky thing” of using python in a string parameter, like vm_picture in a mantra ROP?

That's the one that I started with unfortunately and that's the one I can't get to work. I can get floats to work in a float parameter.

Dave
User Avatar
Member
7750 posts
Joined: July 2005
Offline
First make sure that the parameter is in python mode. Now keyframe it and change the expression.
User Avatar
Member
221 posts
Joined: July 2005
Offline
Ok, so here's what I've tried:

In a mantra ROP, right click on the vm_picture parameter and set a keyframe.

Then I right clicked on the parameter and changed the language to Python. (which you can't do until you set a keyframe).

Then I replaced the expression (ip) with hou.pwd().name()

Then if I MMB on the name of the parameter, it puts a dashed line around it, but doesn't evaluate the python expression, it just shows my expression with a dashed line around it.

Do I need to put it in backticks or something, like in hscript?

Dave
User Avatar
Member
7750 posts
Joined: July 2005
Offline
Backticks will always use hscript expressions I think. Hmm … I followed your steps and it seems to work for me. Maybe it's been fixed in the latest H9.5.

Attachments:
python_expr.jpg (66.4 KB)

User Avatar
Member
221 posts
Joined: July 2005
Offline
I'll try it in 9.5 and see how it goes.

Dave
  • Quick Links