Jump to content

Python flipbook generation outputs only one frame


Krion

Recommended Posts

Hi,

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

Link to comment
Share on other sites

  • 2 weeks later...

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 "test007_sc4546_v003_explosion")

so flipbook will take this name "explosion"

 

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):
	os.mkdir(data_folder)


filelist = []
os.path.isdir(flipbook_folder)

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))
		filelist.append(num)

                

mx=0

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"
os.mkdir(version_folder)
os.mkdir(jpg_folder)
os.mkdir(hip_folder)
hip_name_save = hip_folder+"/"+hip_name+".hip"
hou.hipFile.save(hip_name_save)


##### Copy the viewer's current flipbook settings
cur_desktop = hou.ui.curDesktop()
scene = cur_desktop.paneTabOfType(hou.paneTabType.SceneViewer)
flipbook_options = scene.flipbookSettings().stash()
flipbook_options.frameRange((int(range_start),int(range_end)))
flipbook_options.output(file_name)
flipbook_options.gamma(float(gamma_in))
scene.flipbook(scene.curViewport(), flipbook_options)

#newPath = file_name.replace('/', os.sep)
#hou.ui.displayMessage(jpg_folder) 
#os.startfile(jpg_folder)

 

Edited by alex333d
  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...
On 22/05/2020 at 5:10 PM, alex333d said:

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):
	os.mkdir(data_folder)


filelist = []
os.path.isdir(flipbook_folder)

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))
		filelist.append(num)

                

mx=0

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"
os.mkdir(version_folder)
os.mkdir(jpg_folder)
os.mkdir(hip_folder)
hip_name_save = hip_folder+"/"+hip_name+".hip"
hou.hipFile.save(hip_name_save)


##### Copy the viewer's current flipbook settings
cur_desktop = hou.ui.curDesktop()
scene = cur_desktop.paneTabOfType(hou.paneTabType.SceneViewer)
flipbook_options = scene.flipbookSettings().stash()
flipbook_options.frameRange((int(range_start),int(range_end)))
flipbook_options.output(file_name)
flipbook_options.gamma(float(gamma_in))
scene.flipbook(scene.curViewport(), flipbook_options)

#newPath = file_name.replace('/', os.sep)
#hou.ui.displayMessage(jpg_folder) 
#os.startfile(jpg_folder)

 

 

Have to admit that if im getting into VEX now, scripting and python has never been my area of expertise.

It would be great to have a python script, which to from a selected folder, open each hip file, and save a flipbook thumbnail preview image of the last output selected.

Or actually more interesting will be to have it operate every time you save the file, with the jpg preview image with the same name as the hip file...

The script under the Houdini blue print web site is brillant

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...