Python file padding issue

   2308   8   0
User Avatar
Member
143 posts
Joined: March 2014
Offline
Hello,

I'm trying to set a parameter of a string in Python like this:

hou.parm('/obj/global/textb').set(“obj001_001.$F3.png”)

…but the result is this:
obj001_001.001.png

…so it seems to be using the result of the expression instead of using “$F3” instead like this:
obj001_001.$F3.png

How should I format the .set() parameter so it shows “$F3” instead of “001”?

Thank you!
User Avatar
Member
7739 posts
Joined: Sept. 2011
Offline
Your example is correct.
User Avatar
Member
143 posts
Joined: March 2014
Offline
Hi I'm not sure what you mean - the result I'm getting is not the desired result. I wish for the result in the text string box to be:
obj001_001.$F3.png
User Avatar
Member
1904 posts
Joined: Nov. 2006
Online
What you are doing is correct. I have no problems running a hou.Parm.set(“foo.$F4.bgeo”) on a string parameter and getting the expected value in the interface field:

>>> hou.parm('/obj/geo1/font1/text').set("foo.$F4.bgeo")
>>> hou.parm('/obj/geo1/font1/text').unexpandedString()
'foo.$F4.bgeo'
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
143 posts
Joined: March 2014
Offline
hmmm. What I've done was “Edit parameter interface” of a Null named “global”, then added a string parameter named “textb”. The result of my python call is not the same result as yours(the “$F4”), my result is the expanded string (“001”). FYI the python call is in the Post-Render Script of an OpenGL ROP; not sure if that matters. (i tried adding screenshots but it wouldn't take)
Edited by caesar - March 21, 2017 21:07:09
User Avatar
Member
7739 posts
Joined: Sept. 2011
Offline
That's different. The post render script is evaluating the ‘$F3’ before the python ever gets executed. I'm not sure what you can do to prevent this. Maybe use a formatting string to inject the ‘$’ so it is never next to an ‘F’.
hou.parm('/obj/geo1/font1/text').set("foo.{}F4.bgeo".format("$"))
User Avatar
Member
143 posts
Joined: March 2014
Offline
Hi ok I figured it out. You have to escape the “$” like this:

hou.parm('/obj/global/textb').set(“obj001_001.\$F3.png”)

Thanks!! You led me down the right path
User Avatar
Member
7739 posts
Joined: Sept. 2011
Offline
I was going to suggest escaping it, but I've found ‘$’ variables to be particularly stubborn about escaping sometimes.
User Avatar
Member
143 posts
Joined: March 2014
Offline
Thank you again though for helping. I appreciate it a lot.
  • Quick Links