Can $F be written in a Houdini node's parameter via Python?

   1046   6   1
User Avatar
Member
2 posts
Joined: Nov. 2022
Offline
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)

User Avatar
Member
146 posts
Joined: June 2016
Offline
You should use this function.


setExpression(expression)
Mohan Pugaz
movfx
https://www.instagram.com/movfx/ [www.instagram.com]
https://www.youtube.com/channel/@_movfx
User Avatar
Member
1 posts
Joined: April 2021
Offline
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)

User Avatar
Member
146 posts
Joined: June 2016
Offline
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)
Mohan Pugaz
movfx
https://www.instagram.com/movfx/ [www.instagram.com]
https://www.youtube.com/channel/@_movfx
User Avatar
Member
8839 posts
Joined: July 2007
Offline
$ 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
User Avatar
Member
146 posts
Joined: June 2016
Offline
Feels Great to get an answer from one of the legends of the forum.

Thanks a lot Tomas!
Mohan Pugaz
movfx
https://www.instagram.com/movfx/ [www.instagram.com]
https://www.youtube.com/channel/@_movfx
User Avatar
Member
2 posts
Joined: Nov. 2022
Offline
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)

  • Quick Links