Jump to content

Python flipbook generation outputs only one frame

Recommended Posts


From the sidefx docs I stole this code:

desktop = hou.ui.curDesktop()
viewer = desktop.paneTabOfType(hou.paneTabType.SceneViewer)

# Copy the viewer's current flipbook settings
flipbook_options = viewer.flipbookSettings().stash()

# Change the settings however you need
# (for example, set the frame range and output filename)
parmi = hou.parm("/obj/comments/addtoflipexport")
flipbook_options.frameRange( (1, 5) )
flipbook_options.output("$HIP/flipjes/flipbook_FRM=`padzero(4, $F)`.jpg")

# Generate the flipbook using the modified settings
viewer.flipbook(viewer.curViewport(), flipbook_options)

I did change the normal $F from my original filename to `padzero(4, $F)`, but it still only outputs one frame.

How do I make it update along with the frame number while the scene is generating the flipbook?

Thanks in advance. :) 


python flipbook.hipnc

Share this post

Link to post
Share on other sites
Posted (edited)

You can use this code if you want, it will create small UI with name of flipbook and you can manually set whatever frames do you need.
also it will create two folder: 1 jpg sequence, 2 hip file

Important! You have to have in your project folder "flip" (it will save your flipbooks inside this folder) and the name of hip should containe version, as example


import toolutils
import hou
import os
import sys
import re

from datetime import datetime
### frame range ###
start = hou.expandString('$FSTART')
end = hou.expandString('$FEND')

### ui ###
text_to_search = hou.expandString('$HIPNAME')
pattern = re.compile(r'[v](\d{3})[_](\w*)')
matches = pattern.finditer(str(text_to_search))

for match in matches:
	def_name = str(match.group(2))
	print (match.group(2))

gamma = 0.7
#def_name = "flipbook"
list = ["Name", "Fstart", "Fend", "Gamma"]
list2 = [def_name, str(start), str(end), str(gamma)]
read = hou.ui.readMultiInput("Flipbook settings", list, initial_contents = list2)
range_start = (read[1][1])
range_end = (read[1][2])
gamma_in = (read[1][3])

### folders ###

date = datetime.now().strftime('%d.%m.%Y')
job_folder = hou.expandString('$JOB')
hip_name = hou.expandString('$HIPNAME')
flipbook_folder = job_folder+"/flip"
data_folder = flipbook_folder+"/"+date
version_folder = data_folder + "/v0"

if not os.path.isdir(data_folder):

filelist = []

find = version_folder.rfind('/')
cut_path2 = version_folder[:find]
#print cut_path2

for folder in os.listdir(cut_path2):
	pattern = re.compile("^v(\d*)$")
	result = pattern.match(folder)

	if result is not None:
		num = int(result.group(1))



if len(filelist)!=0:
	mx = max(filelist)
	version = mx+1
	version_folder = data_folder + "/v" + str(version)

jpg_folder = version_folder+"/jpg"
hip_folder = version_folder+"/hip"

file_name  = str(jpg_folder)+"/"+(read[1][0])+".$F4.jpg"
hip_name_save = hip_folder+"/"+hip_name+".hip"

##### Copy the viewer's current flipbook settings
cur_desktop = hou.ui.curDesktop()
scene = cur_desktop.paneTabOfType(hou.paneTabType.SceneViewer)
flipbook_options = scene.flipbookSettings().stash()
scene.flipbook(scene.curViewport(), flipbook_options)

#newPath = file_name.replace('/', os.sep)


Edited by alex333d
  • Thanks 1

Share this post

Link to post
Share on other sites

Thanks for sharing alex333d,

I will look at the code and try it out.

Share this post

Link to post
Share on other sites

$F4 gets evaluated inside the python script so it's "baked" into the code,
there's probably a cleaner way, but this works:

flipbookpath = "/tmp/flipbook/mysim"

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now