Hello,
I'm trying to set the global animation range using python. The Hscript help states tset is replaced by hou.setGlobalFrameRange but this doesn't seem to be implemented yet.
So, I'm trying to call tset from python using hou.hscript(). This works fine, if all I want to do is give it specific values, for example:-
hou.hscript('tset `(1001-1)/$FPS` `1050/$FPS`')
But I want to be able to pass in a python variable for the frame start and frame end values. I thought I had this working when I defined a couple of variables in the python shell ('start' and ‘end’) and used:-
hou.hscript('tset `(pythonexprf(“start”)-1)/$FPS` `pythonexprf(“end”)/$FPS`')
and got success, but for some reason if I do the exact same in a shelf tool this doesn't work. It seems to still be taking precedence from the variables defined in the python shell, not the shelf tool script. If the variables haven't been defined in the python shell previously but are defined in the shelf tool script, I get traceback errors telling me the variable is not defined.
Any Python Guru's care to shed some light on this?
Thanks!
Setting global animation range with python/hscript
15682 9 2- Dean_19
- Member
- 319 posts
- Joined:
- Offline
- Dean_19
- Member
- 319 posts
- Joined:
- Offline
- Anonymous
- Member
- 678 posts
- Joined: July 2005
- Offline
- Anonymous
- Member
- 678 posts
- Joined: July 2005
- Offline
Dean_19
setGobalFrangeExpr = ‘tset `(%d-1)/$FPS` `%d/$FPS`’ % (start_frame,end_frame)
Stay away from “%” for string formating in python since it's going belly up from version 3 up so your script will not work when Houdini will switch to it. Use instead proper string formating that works in 2.6 and higher versions too:
setGobalFrangeExpr = “tset `({0}-1)/$FPS` `{1}/$FPS`”.format(start_frame,end_frame)
- ben-andersen
- Member
- 47 posts
- Joined: Jan. 2014
- Offline
I don't think the printf style formatting is going away in python 3.
https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting [docs.python.org]
Python 3 just introduces a more flexible alternative to it as well.
https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting [docs.python.org]
Python 3 just introduces a more flexible alternative to it as well.
- rc.work
- Member
- 3 posts
- Joined: Aug. 2013
- Offline
- ben-andersen
- Member
- 47 posts
- Joined: Jan. 2014
- Offline
- Anonymous
- Member
- 678 posts
- Joined: July 2005
- Offline
Ben Andersen
I don't think the printf style formatting is going away in python 3.
https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting [docs.python.org]
Python 3 just introduces a more flexible alternative to it as well.
PEP 3101: Advanced String Formatting. Note: the 2.6 description mentions the format() method for both 8-bit and Unicode strings. In 3.0, only the str type (text strings with Unicode support) supports this method; the bytes type does not. The plan is to eventually make this the only API for string formatting, and to start deprecating the % operator in Python 3.1.
https://docs.python.org/3.1/whatsnew/3.0.html [docs.python.org]
- xjorma
- Member
- 1 posts
- Joined: Oct. 2017
- Offline
- jsmack
- Member
- 7802 posts
- Joined: Sept. 2011
- Offline
-
- Quick Links