Can $F be written in a Houdini node's parameter via Python?
1045
6
1
houetuya
Member
2 posts
Joined: Nov. 2022
Offline
June 13, 2024 9:04 a.m.
Is it possible to write $F in the integer parameter of a node created with Python in Houdini?
I want to put $F-1 in the parameter of a Switch created with Python, but in the current code, it is changed to the frame number at the moment of creation.
Please advise.
import hou
import os
switchNode = hou . node ( "." ) . createNode ( "switch" )
expression = str ( $ F )
switchNode . parm ( "input" ) . set ( str ( expression ))
Edited by houetuya - June 13, 2024 10:20:57
Attachments:
Untitled.png (27.0 KB)
Untitled (2).png (25.7 KB)
Untitled (1).png (5.2 KB)
Mohanpugaz
Member
146 posts
Joined: June 2016
Offline
June 13, 2024 12:14 p.m.
You should use this function.
setExpression(expression)
June 14, 2024 2:20 a.m.
Thank you.
I tried using `.setExpression(expression)`, but `$F` gets converted to the frame number at the time of creation.
I couldn't input the desired `$F+1` expression directly into the parameter.
import hou
import os
switchNode = hou . node ( "." ) . createNode ( "switch" )
expression = str ( $ F + 1 )
switchNode . parm ( "input" ) . setExpression ( expression )
Attachments:
Untitled.png (27.1 KB)
Untitled (1).png (12.8 KB)
setExpression.hip (69.3 KB)
Mohanpugaz
Member
146 posts
Joined: June 2016
Offline
June 14, 2024 10:28 a.m.
I just opened your hip file and had a look.
It looks like the exec() function is doing something here.
If you run the same script from the python source editor it sets the expression properly.
I dont have a solution for this case, but what i would do is make the subnet into hda and call the script from hda module so i can avoid the exec function.
Im too interested to know why this doesnt work when calling a script with exec() and how to fix.
Waiting for the experts!
import hou
switch = hou . node ( "/obj/geo1" ) . createNode ( "switch" )
exp = "$F4"
switch . parm ( "input" ) . setExpression ( exp )
tamte
Member
8839 posts
Joined: July 2007
Offline
June 15, 2024 3:54 a.m.
$ variables within string parameters are evaluated so that's why you are seeing the literal value replacing your $F
if you want to insert $F you need to escape the $ so write \$F
import hou
import os
switchNode = hou . node ( "." ) . createNode ( "switch" )
expression = "\$F+1"
switchNode . parm ( "input" ) . setExpression ( expression )
Edited by tamte - June 15, 2024 03:55:20
Tomas Slancik FX Supervisor Method Studios, NY
Mohanpugaz
Member
146 posts
Joined: June 2016
Offline
June 15, 2024 4:53 a.m.
Feels Great to get an answer from one of the legends of the forum. Thanks a lot Tomas!
houetuya
Member
2 posts
Joined: Nov. 2022
Offline
June 15, 2024 8:36 a.m.
Thanks. That works. I truly appreciate this help. Thank you so much.
Edited by houetuya - June 15, 2024 08:41:36
Attachments:
rapture_20240615214115.png (148.6 KB)