Changing viewport lighting through python

   2101   2   1
User Avatar
Member
17 posts
Joined: Nov. 2017
Offline
I am trying to change the lighting of my current viewport in python. (More precisely disable all lighting)
There are some documentation about functions to do that, but I cannot seem to make it work.

With information from here: http://www.sidefx.com/docs/houdini/hom/tool_script.html [www.sidefx.com]
And here: http://www.sidefx.com/docs/houdini/hom/hou/GeometryViewportSettings.html [www.sidefx.com]

I tried the following code:
scene_view = toolutils.sceneViewer()
viewport = scene_view.curViewport()
viewportsettings=viewport.settings()
viewportsettings.setLighting(hou.viewportLighting.Off)
#Return: AttributeError: 'GeometryViewportSettings' object has no attribute 'setLighting'

Why am I getting this AttributeError: ‘GeometryViewportSettings’ object has no attribute ‘setLighting’ ?
This page [www.sidefx.com] clearly says that the GeometryViewportSettings class has a function setLighting.
I must be missing something really stupid, I know it !


On another side, I read this post: https://www.sidefx.com/forum/topic/41699/ [www.sidefx.com]
that mention this:
The lighting modes aren't directly represented by a single setting in the viewport, they're more like macros that set these 4 settings:

viewlight -l on|off // Lighting on/off
vieweroption -h on|off // Headlight on/off
viewlight -h on|off // HQ Lighting on/off
viewdisplay -X on|off // shadows on/off

Therefor I try the following:
hou.hscript("viewlight -l off")
But this one gets me this error message:
'', ‘viewlight: Invalid usage\nviewlight\n\n Controls viewport settings.\n\n This command is used internally by Houdini to save the options set\n on a viewport.\n\n RELATED\n\n * viewdispopts\n\n * viewdispset\n\n’)
Edited by JulienH - Dec. 4, 2017 07:09:51
User Avatar
Staff
5296 posts
Joined: July 2005
Offline
This was added very recently in 16.5.309. I suspect you might have to upgrade Houdini to that version or greater.

As for the hscript, “viewlight” requires the name of a viewport, as reported by “viewls”, eg:

viewlight -l off Build.panetab1.world.persp1

But if you can do the upgrade, use HOM instead.
User Avatar
Member
17 posts
Joined: Nov. 2017
Offline
Sorry for the late answer, thank you twod !
Indeed I did not have the last version !
  • Quick Links