dziga kaiser

dzigakaiser

About Me

creating worlds for screen and paper - dziga.com
EXPERTISE
Freelancer
INDUSTRY
Film/TV

Connect

LOCATION
Germany

Houdini Skills

Availability

Not Specified

Recent Forum Posts

HDA Python - create cam and frame selected geo issues Nov. 17, 2021, 7:05 a.m.

Hey Juanjo!

It's never too late

Adjusted my code to your method as it will probably be more stable than mine ^.^

Thanks a lot for sharing your findings!

Take care,
Dziga

Pyhton frame selected July 17, 2021, 7:53 a.m.

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

Is that possible to save .sim file when simulation is done? July 14, 2021, 3:44 p.m.

Hi Jisung,

I felt like trying to tackle your issue from another angle^.^ Attached you find a file with a Python based solution.

What it does:
1. When a frame is cooked, it adds the sim file name to a log file in the simulation directory.
2. It keeps the last X names in the log (you choose how many you want to keep in the Python SOP).
3. When a frame cooks, it deletes all other sim files except the last X amount.

What you have to do:
1. Connect the Python SOP to your dopnet, so it cooks each frame.
2. In the very top of the code section you see "USER INPUT".
2a. Add the path to your dopnet output node with which you save the sim files to disk.
2b. Enter the number of files you wish to keep (default = 3)

Known issue so far:
1. When you re-cache a sim that is still in memory, it seems to save the files to disk without cooking the Python code and thus not deleting files.
2. I would disable the Python SOP whenever you are not caching to disk. Otherwise it might get confused about which files to keep because of the way I wrote the script. Could be optimized ^^

The rest should work as is. In case you encounter errors, don't hesitate to contact me. I only tested on my Windows workstation with the simple file I uploaded.
There might be issues with other OS or file permissions, though it should work for Linux as well.

Let me know if this is what you wanted ^.^



Good luck!
Dziga