How to change viewport color, disable grid from Python

   2005   4   1
User Avatar
Member
117 posts
Joined: Feb. 2015
Offline
I have been trying all day to set the viewport background to black and disable the grid from Python.

I got this far, so I managed to get the viewport and I set it to dark, but nothing happens.
Any ideas?
What I try to do is setup the scene so its better before generating a flipbook.

####To get the viewport
a = hou.ui.paneTabOfType(hou.paneTabType.SceneViewer)
b = a.viewports()
tviewport = b #this will get the perspective viewport
tviewport.home() #will focus it home
tview_settings = tviewport.settings()
tview_settings.setColorScheme = hou.viewportColorScheme.Dark
User Avatar
Staff
5212 posts
Joined: July 2005
Offline
The other option is to set the flipbook to render "Beauty Pass Only" which will avoid rendering the background gradient, grid, handles, etc, making it much closer to a render (Render - Current Viewport -> Beauty Pass Only in the flipbook dialog).
User Avatar
Member
117 posts
Joined: Feb. 2015
Offline
Thanks that is helpful. I still have a few issues with the beauty pass
For example it will still render the objects with visible edges if that was set in the viewport (which is normally what I have while working). But yes, it fixed the background and got rid of gizmos which is useful.
One weird thing is that the lighting is much darker with the beauty pass. Hmm, I notice mplay looks fine, but the jpg that I save are darker when I use the beauty pass. Not sure why
Edited by AndreasOberg - Oct. 21, 2022 04:54:38
User Avatar
Member
1 posts
Joined: May 2017
Offline
Hi, nothing is happening because you're actually querying the colorScheme instead of setting it.

So, the correct last line should be :
tview_settings.setColorScheme(hou.viewportColorScheme.Dark)
instead of :
tview_settings.setColorScheme = hou.viewportColorScheme.Dark

(I know that this is an old post, but it's the 1st google result, I'm replying just in case of someone is searching the same thing)
User Avatar
Member
146 posts
Joined: June 2016
Offline
A quick snippet which can be added to shelf tool
this cycles between dark,light,and grey viewport bgs.

Just create a new shelf tool and add this code in the scripts section and don't forgot to set it to python.

## python snippet
def cycle_display_bg():
# init available schemes
light = hou.viewportColorScheme.Light
dark = hou.viewportColorScheme.Dark
grey = hou.viewportColorScheme.Grey

# add them to a list
schemes = [light,dark,grey]

# find the viewport display settings
viewport = hou.ui.curDesktop().paneTabOfType(hou.paneTabType.SceneViewer)
display_settings = viewport.curViewport().settings()

# apply the sceme
current_scheme = display_settings.colorScheme()

for s in schemes:
if s == current_scheme:
next_id = schemes.index(s)+1
next_id = next_id % len(schemes)
next_scheme = schemes[next_id]
display_settings.setColorScheme(next_scheme)
msg = f"viewport background set to {next_scheme.name()}"
hou.ui.setStatusMessage(msg)
return


cycle_display_bg()
### follow me on instagram @movfx

Thanks!
Mohan Pugaz
movfx
https://www.instagram.com/movfx/ [www.instagram.com]
https://www.youtube.com/channel/@_movfx
  • Quick Links