Jump to content

Viewport Changed Python

Recommended Posts


I've written a little python expression to scale geo dependent on through which camera is being viewed. It works but does not recognise when the viewport has changed - is there an event trigger I can use to get it to recognise this change?


import hou

desktop = hou.ui.curDesktop()
scene_viewer = desktop.paneTabOfType(hou.paneTabType.SceneViewer)
viewport = scene_viewer.curViewport()

camera = hou.GeometryViewport.camera(viewport)

if 'preview' in str(camera):
    return 0.01
    print 'preview cam'
    return 1

Share this post

Link to post
Share on other sites

If you look at a recent post I made here, Alex Rusev gave me an excellent solution for getting an event trigger when a new node is selected. I strongly suspect you could use the same mechanism for finding out when the viewport changes. Essentially you just add a new eventLoopCallback() that compares the current viewport to a previously-stored viewport, and if they are different then do a thing (in my case, I needed to emit a Qt signal, in your case, scale geo). Not sure what your level of python is, but if you need help writing it I'll probably have some time to figure it out with you a little later today :)

Share this post

Link to post
Share on other sites

thanks - it's way overkill for what I need but it's good to know it's do-able

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