Setting global animation range with python/hscript

   15832   9   2
User Avatar
Member
319 posts
Joined:
Offline
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!
User Avatar
Member
319 posts
Joined:
Offline
A colleague solved this for me with the magic of %d:-

start_frame = 1020
end_frame = 1050

setGobalFrangeExpr = ‘tset `(%d-1)/$FPS` `%d/$FPS`’ % (start_frame,end_frame)

hou.hscript(setGobalFrangeExpr)
User Avatar
Member
678 posts
Joined: July 2005
Offline
satisfied answer
User Avatar
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)
User Avatar
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.
User Avatar
Member
3 posts
Joined: Aug. 2013
Offline
hou.playbar.setPlaybackRange(self, start, end)

no?
User Avatar
Member
47 posts
Joined: Jan. 2014
Offline
I think hou.playbar.setPlaybackRange() just sets the playback range, not the actual scene frame range. So the hou interface would set $RFSTART but not $FSTART.
User Avatar
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]
User Avatar
Member
1 posts
Joined: Oct. 2017
Offline
hou.playbar.setFrameRange(start, end)seems to do the job now.
User Avatar
Member
7865 posts
Joined: Sept. 2011
Online
hou.playbar.setPlaybackRange(start, end) may also need to be called if the playback range differs from the scene range.
  • Quick Links