Viewport Screenshot
12651 17 3- erikcarlson
- Member
- 19 posts
- Joined: Dec. 2015
- Offline
- Alexey Vanzhula
- Member
- 538 posts
- Joined: Dec. 2006
- Offline
Create shelf tool with script:
from time import gmtime, strftime
# GET VIEWPORT CAMERA PATH
cur_desktop = hou.ui.curDesktop()
desktop = cur_desktop.name()
panetab = cur_desktop.paneTabOfType(hou.paneTabType.SceneViewer).name()
persp = cur_desktop.paneTabOfType(hou.paneTabType.SceneViewer).curViewport().name()
camera_path = desktop + “.” + panetab + “.” + “world” “.” + persp
# BUILD DEFAULT FILE NAME FROM CURRENT TIME
default_filename = strftime(“screenshot_%d_%b_%Y_%H_%M_%S.jpg”, gmtime())
# SELECT FILE
filename = hou.ui.selectFile( title='Select Screenshot File', default_value=default_filename, file_type=hou.fileType.Image )
# WRITE TO FILE
if filename is not None:
frame = hou.frame()
hou.hscript( “viewwrite -f %d %d %s ‘%s’” % (frame, frame, camera_path, filename) )
from time import gmtime, strftime
# GET VIEWPORT CAMERA PATH
cur_desktop = hou.ui.curDesktop()
desktop = cur_desktop.name()
panetab = cur_desktop.paneTabOfType(hou.paneTabType.SceneViewer).name()
persp = cur_desktop.paneTabOfType(hou.paneTabType.SceneViewer).curViewport().name()
camera_path = desktop + “.” + panetab + “.” + “world” “.” + persp
# BUILD DEFAULT FILE NAME FROM CURRENT TIME
default_filename = strftime(“screenshot_%d_%b_%Y_%H_%M_%S.jpg”, gmtime())
# SELECT FILE
filename = hou.ui.selectFile( title='Select Screenshot File', default_value=default_filename, file_type=hou.fileType.Image )
# WRITE TO FILE
if filename is not None:
frame = hou.frame()
hou.hscript( “viewwrite -f %d %d %s ‘%s’” % (frame, frame, camera_path, filename) )
- erikcarlson
- Member
- 19 posts
- Joined: Dec. 2015
- Offline
- Mohanpugaz
- Member
- 130 posts
- Joined: June 2016
- Offline
That is cool trick to know.. thanks for sharing Vux!
Mohan Pugaz
movfx
https://www.instagram.com/movfx/ [www.instagram.com]
https://www.youtube.com/channel/@_movfx
movfx
https://www.instagram.com/movfx/ [www.instagram.com]
https://www.youtube.com/channel/@_movfx
- goldfarb
- Staff
- 3455 posts
- Joined: July 2005
- Offline
- cb
- Staff
- 635 posts
- Joined: July 2005
- Offline
elveatles
Is it possible to save what is currently in the active viewport using Python? Like flipbook for just one frame. I cannot find a way to do this and would really appreciate help.
There is also something called an “OpenGL ROP” in Houdini. I don't think it's quite what you want in this particular case, but it may serve you well in other instances when you just need a quick render of your geometry.
Cristin
- Mohanpugaz
- Member
- 130 posts
- Joined: June 2016
- Offline
vux
Create shelf tool with script:
from time import gmtime, strftime
# GET VIEWPORT CAMERA PATH
cur_desktop = hou.ui.curDesktop()
desktop = cur_desktop.name()
panetab = cur_desktop.paneTabOfType(hou.paneTabType.SceneViewer).name()
persp = cur_desktop.paneTabOfType(hou.paneTabType.SceneViewer).curViewport().name()
camera_path = desktop + “.” + panetab + “.” + “world” “.” + persp
# BUILD DEFAULT FILE NAME FROM CURRENT TIME
default_filename = strftime(“screenshot_%d_%b_%Y_%H_%M_%S.jpg”, gmtime())
# SELECT FILE
filename = hou.ui.selectFile( title='Select Screenshot File', default_value=default_filename, file_type=hou.fileType.Image )
# WRITE TO FILE
if filename is not None:
frame = hou.frame()
hou.hscript( “viewwrite -f %d %d %s ‘%s’” % (frame, frame, camera_path, filename) )
For all of you who try to use VUX's script.
I copy pasted this script and it doesnt work at first.
Because there is something wrong with the double quotes,
I just deleted the quotes and retyped them that works perfectly
Thanks a lot to VUX for this script its really useful for me
Mohan Pugaz
movfx
https://www.instagram.com/movfx/ [www.instagram.com]
https://www.youtube.com/channel/@_movfx
movfx
https://www.instagram.com/movfx/ [www.instagram.com]
https://www.youtube.com/channel/@_movfx
- malexander
- Staff
- 5156 posts
- Joined: July 2005
- Offline
Note that H16.0 added HOM support for flipbooking directly, so that you could do the entire script in HOM now without the hscript(“viewwrite”) command.
scene = cur_desktop.paneTabOfType(hou.paneTabType.SceneViewer) flip_options = scene.flipbookSettings().stash() flip_options.frameRange( (frame, frame) ) flip_options.output(filename) scene.flipbook(scene.curViewport(), flip_options)
- Mohanpugaz
- Member
- 130 posts
- Joined: June 2016
- Offline
Really cool to know , thanks for the useful info and code
Mohan Pugaz
movfx
https://www.instagram.com/movfx/ [www.instagram.com]
https://www.youtube.com/channel/@_movfx
movfx
https://www.instagram.com/movfx/ [www.instagram.com]
https://www.youtube.com/channel/@_movfx
- animatrix_
- Member
- 4495 posts
- Joined: Feb. 2012
- Offline
Can we now both launch the flipbook window and also save the result on disk in H16? Before it wasn't possible. For example auto save flipbook on disk while also showing it interactively flipbooking using mplay?
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
- malexander
- Staff
- 5156 posts
- Joined: July 2005
- Offline
- animatrix_
- Member
- 4495 posts
- Joined: Feb. 2012
- Offline
Thanks Mark that's what I wanted to do. I was told before it couldn't be done.
ID #72062
I thought once I launch flipbook, I can't control mplay anymore. Any idea how would this look like in pseudo code?
ID #72062
I thought once I launch flipbook, I can't control mplay anymore. Any idea how would this look like in pseudo code?
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
- landyvfx
- Member
- 8 posts
- Joined: Sept. 2017
- Offline
- Andr
- Member
- 900 posts
- Joined: Feb. 2016
- Offline
Hello, I have to bump this old discussion.
I tried the code, which works super fine, but it popups the save dialog.
I need it to automatically write the viewport.jpg to disk, as fast as possible, as my trying to do a batch export of the crude geometry in the viewport. No need fancy stuff like AA, or shadows. Headlight only.
Ideally it should save the viewport_$F.jpg just after houdini cooks the frame. (so no save sequence)
I had a look at the hou.FlipbookSettings class [www.sidefx.com] , but couldn't find any method to automatically skip the save dialog, and write the file to disk.
thanks for any advice!
I tried the code, which works super fine, but it popups the save dialog.
I need it to automatically write the viewport.jpg to disk, as fast as possible, as my trying to do a batch export of the crude geometry in the viewport. No need fancy stuff like AA, or shadows. Headlight only.
Ideally it should save the viewport_$F.jpg just after houdini cooks the frame. (so no save sequence)
I had a look at the hou.FlipbookSettings class [www.sidefx.com] , but couldn't find any method to automatically skip the save dialog, and write the file to disk.
thanks for any advice!
- Andr
- Member
- 900 posts
- Joined: Feb. 2016
- Offline
Should I go this way maybe?
https://pypi.org/project/pyscreenshot/ [pypi.org]
External module to take screenshots and save them to disk.
*Edit*
I guess I should use the openGL render node.
https://pypi.org/project/pyscreenshot/ [pypi.org]
External module to take screenshots and save them to disk.
*Edit*
I guess I should use the openGL render node.
Edited by Andr - Nov. 13, 2018 16:21:33
- jsmack
- Member
- 7741 posts
- Joined: Sept. 2011
- Offline
- Andr
- Member
- 900 posts
- Joined: Feb. 2016
- Offline
- sdugaro
- Member
- 380 posts
- Joined: July 2005
- Offline
This was a tad annoying for me in H19.0.455 as the MPlay window would launch by default whenever I invoked the render -- until I discovered that outputToMplay() is True by default.
import traceback from os.path import dirname,basename,splitext def getSceneViewer(): """ return an instance of a visible viewport. There may be many, some could be closed, any visible are current """ panetabs = hou.ui.paneTabs() panetabs = [x for x in panetabs if x.type() == hou.paneTabType.SceneViewer] panetabs = sorted(panetabs, key=lambda x: x.isCurrentTab()) if panetabs: return panetabs[-1] else: print("No SceneViewers detected.") return None def viewwrite(): """ Get the current sceneviewer (may be more than one or hidden) and screengrab the perspective viewport to a file in the publish location to be picked up with the publish. Note that .png output will render pooly, so use .jpg """ try: node = hou.node(".") path = node.parm("outputpath").eval() file,ext = splitext(basename(path)) filename = f'{dirname(path)}/{file}.jpg' frame = hou.frame() desktop = hou.ui.curDesktop() sceneview = getSceneViewer() viewport = sceneview.curViewport() # this will open an mplay window to show the result fbs = sceneview.flipbookSettings().stash() fbs.frameRange( (frame, frame) ) fbs.output(filename) fbs.outputToMPlay(False) sceneview.flipbook(viewport, fbs) except Exception as e: print(f'ERROR: Failed to Capture Viewport\n{traceback.format_exc(2)}')
-
- Quick Links