Jump to content

python setExpression problems


j00ey

Recommended Posts

I'm fairly new to python and I've written some code that generates a load of nodes, wires them up and so on and also a load of mantra ROPs.

 

I'm now trying to write a custom prerender script that varies for each according to a couple of variables. That part is working fine but I can't figure out how to set the expression language to python.

 

Here's the relevant code - 

 

prerender=mantraRop.parm('prerender')       prerender.setExpression('metalswitch=hou.node(\'/obj/metalGeo/switch_metal_materials\')\ninput=metalswitch.parm(\'input\')\ninput.set(%s)'%int(metalnum))
 
from the help:
To change the expression language, use hou.Parm.setExpression and explicitly specify the language: parm.setExpression(parm.expression(), language).
 
so I've tried putting all sorts before the closing brackets [with a comma between] - 'python', python, Python, 'Python,0,1
Nothing works!
Can someone help?
 
Thanks very much
 
Link to comment
Share on other sites

For the render related scripts I usually don't actually set an expression in the field and just put the raw text in while setting the corresponding script language parm to Python.  If your code is an expression Houdini can/will actually evaluate the code when the parm interface is displayed.  If it isn't this won't happen and Houdini will just run it as raw code when the script is run.

  • Like 1
Link to comment
Share on other sites

Hi

Thanks very much for the input.

 

Ayidi - I will look into that tomorrow but you are saying it is possible to set the language with exprLanguage?

 

Graham - without being able to try it out that's a bit beyond me. I need the interface itself not to be displayed, or that is to say I don't want to have to display each interface but I might need to do for some reason or other. How do you put a string in without setExpression()? I did try just setting the value to a string but it wanted an int. Or am I getting mixed up? It certainly wouldn't let me set a switchSop input parm to a string without setExpression().

 

I'm not able to look at anything today any more but I will try again over the weekend. Thanks again

Link to comment
Share on other sites

Took me a little while to figure out but I got it working. Thanks again both for your help though Graham, your advice is a bit over my head for the moment. I will come back to it once I'm more familiar with Python.

 

In case anyone else comes across the same problem, this is a working version : 

 

prerender.setExpression('metalswitch=hou.node(\'/obj/metalGeo/switch_metal_materials\')\ninput=metalswitch.parm(\'input\')\ninput.set(%s)'%int(metalnum),hou.exprLanguage.Python)

 

simplified to:

 

prerender.setExpression('myExpression',hou.exprLanguage.Python)

 

 

One other question - I need to continue writing the expression for another few lines, is there any way of putting in a line break in the code so in my editor it doesn't just run on for ever?

  • Like 1
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...