Jump to content

Python - frameSelected() function not working


Recommended Posts

Hey guys!

Once again, I have to seek out your precious help ^.^

I am currently creating my own asset browser and I am working on feeding assets from Houdini into the library.

So far, everything was going pretty smoothly up until I got stuck with something that seems so simple: the frameSelected() function of the hou.GeometryViewport class.

When I use the Python shell inside Houdini and do this, it is working correctly:

import toolutils
viewer = toolutils.sceneViewer()
view = viewer.curViewport()
node = hou.node('/obj/geo1/DZK_Asset_Export')
node.setCurrent(True,True)
view.frameSelected()

My section in the HDA is not. Broken down to the essential part (with hard coded selection of node as above for the sake of the example):

import toolutils

viewer = toolutils.sceneViewer()
view = viewer.curViewport()
[...]
cam = obj_level.createNode('cam', 'asset_cam')
node = hou.node('/obj/geo1/DZK_Asset_Export')
node.setCurrent(True,True)
view.frameSelected()
view.saveViewToCamera(cam)
view.setCamera(cam)

All the other functions work as expected (lockCameraToView, saveViewToCamera, setCamera all work fine).

I only have trouble with frameSelected(), even when adding the code from the shell to my script, basically hard coding selecting the correct node.

After running my export process which does not frame the view, I can go to the shell and call frameSelected() and from there it works again :/

I also have sections where I first set the camera, lock the view, then try framing but it is the same result: all working, except the framing.

I wonder what I am doing wrong in my code and hope you can help me out.

 

Any pointers, comments are greatly appreciated!

 

Link to comment
Share on other sites

Okay, I got a little further now. When using setSelected(True,True) instead of setCurrent(True, True) I almost get it to work:

When I click my HDA SOP and run the code, it does not frame the SOP. If I click next to it and then run the code from the parameter interface, it works. 

I added a print statement for hou.selectedNodes() before calling frameSelected() and the output is identical (1st line: clicking on the SOP/ 2nd line: clicking into an empty area in the node graph after having the SOP selected):

(<hou.SopNode of type DZK_asset_export at /obj/geo1/DZK_Asset_Export>,)
(<hou.SopNode of type DZK_asset_export at /obj/geo1/DZK_Asset_Export>,)

Both methods result in also having the node return True for isCurrent(). I am not quite sure what to actually take from this and where to go next :o

Edited by dzigakaiser
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...