Hello,
I'm trying to make a python script to select a node and frame the view in that node. Have solve the selection part but cannot find how to frame in the viewport. Was checking the sceneViewer commands but cannot find anything to frame in the view there.
Pyhton frame selected
4618 4 1- jegupi
- Member
- 13 posts
- Joined: 12月 2018
- Offline
- N-G
- Member
- 209 posts
- Joined: 3月 2018
- Offline
Did you use hou.setFrame()?
https://www.sidefx.com/docs/houdini/hom/hou/setFrame.html [www.sidefx.com]
https://www.sidefx.com/docs/houdini/hom/hou/setFrame.html [www.sidefx.com]
- dzigakaiser
- Member
- 17 posts
- Joined: 8月 2012
- Offline
In theory it is this:
For me this works fine inside the Python shell or a Python SOP but I am having trouble using it in external Python scripts of my HDA. It somehow does not want to frame it from there:/
Maybe you will have more success there.
import toolutils viewer = toolutils.sceneViewer() view = viewer.curViewport() view.frameSelected()
For me this works fine inside the Python shell or a Python SOP but I am having trouble using it in external Python scripts of my HDA. It somehow does not want to frame it from there:/
Maybe you will have more success there.
freelance matte painter & environment concept artist
- andehpandeh
- Member
- 25 posts
- Joined: 3月 2019
- Offline
#get the render cam cam = hou.node('/obj/renderCAM') #get a sphere to focus on sphere = hou.node('/obj/sphere1/sphere1') #move the cam to focus on the bounding box of the sphere bBox = sphere.geometry().boundingBox() #set viewport to the render camera & frame the bounding box view = toolutils.sceneViewer().curViewport() view.setCamera(cam) view.lockCameraToView(True) view.frameBoundingBox(bBox)
Here's a little sample of accessing a cam and geometry, getting the bounding box of the geo and then framing the geo
in the viewport.
A problem that I've had is that everything works (the viewport switches to the render cam, locks the view) except .frameBoundingBox(), but if I run the code a second time, it will frame the camera to the bounding box of the geometry.
Any ideas on how to get the code to work by only running it once?
Edited by andehpandeh - 2021年7月16日 13:48:09
- dzigakaiser
- Member
- 17 posts
- Joined: 8月 2012
- Offline
andehpandeh#get the render cam cam = hou.node('/obj/renderCAM') #get a sphere to focus on sphere = hou.node('/obj/sphere1/sphere1') #move the cam to focus on the bounding box of the sphere bBox = sphere.geometry().boundingBox() #set viewport to the render camera & frame the bounding box view = toolutils.sceneViewer().curViewport() view.setCamera(cam) view.lockCameraToView(True) view.frameBoundingBox(bBox)
Here's a little sample of accessing a cam and geometry, getting the bounding box of the geo and then framing the geo
in the viewport.
A problem that I've had is that everything works (the viewport switches to the render cam, locks the view) except .frameBoundingBox(), but if I run the code a second time, it will frame the camera to the bounding box of the geometry.
Any ideas on how to get the code to work by only running it once?
Hi andehpandeh,
the way I wrote it and it seems to work so far is this:
cam = obj_level.createNode('cam', 'asset_cam') node.setSelected(True,True) view.frameSelected() view.saveViewToCamera(cam) view.setCamera(cam)
The difference is that I create a new cam that frames the selected node.
If I already have a specific camera, I set it up manually and my tool uses it as is.
Possibly this will work for you as well to create a brand new cam. Or maybe you just need the saveViewToCamera() after framing, and then setting the cam in the viewport again.
So I would try this first in your case:
#get the render cam cam = hou.node('/obj/renderCAM') #get a sphere to focus on sphere = hou.node('/obj/sphere1/sphere1') #move the cam to focus on the bounding box of the sphere #bBox = sphere.geometry().boundingBox() #set viewport to the render camera & frame the bounding box view = toolutils.sceneViewer().curViewport() # view.setCamera(cam) view.lockCameraToView(True) sphere.setSelected(True, True) view.frameSelected() view.saveViewToCamera(cam) view.setCamera(cam)
You can of course also try this approach with the bbox instead ^.^
Let me know if this works! I am curious.
Good luck!
Dziga
freelance matte painter & environment concept artist
-
- Quick Links