Hi,
I have this code that creates new node:
new_node = hou.node('/obj').createNode('node_name')
Is there a way to retrieve the current opened context so that this part changes depending on the opened context?
hou.node('/obj')
Hi,
I have this code that creates new node:
new_node = hou.node('/obj').createNode('node_name')
Is there a way to retrieve the current opened context so that this part changes depending on the opened context?
hou.node('/obj')
Are you looking for hou.pwd()
?
Thanks for the response @BigRoyNL
but it somehow always returns the topmost context.
For example, whether I am at hou.node('/obj')
or at hou.node('/obj/geo1')
it always gives me a the following hou.node
<hou.Node at />
Am I missing something?
How do you mean - where you are ācurrentlyā at?
When calling hou.pwd()
from e.g. a node callback thatās when it returns the current node as that is the node executing the logic. For example you could use it within a Python SOP node. (which I think it actually also does by default when creating a node).
Getting the current ācontextā from the UI however is slightly more involved. This is due to how you can e.g. have multiple network views open that each point to a different context. Which one would you want?
Where and when are you trying to retrieve the current context? And what would your expected result be?
Ah gotcha. Iām not using a Python SOP node.
My use case is creating a custom PySide UI with buttons for my commonly modified nodes.
When I click the buttons, it creates a node on the currently opened context.
For testing, Iām using the Python Shell which unfortunately gives me the <hou.Node at />
result.
You could try and get the active pane in Houdini in a multitude of ways. Potentially hou.Desktop.paneTabUnderCursor
or hou.Desktop.paneUnderCursor
could help?
Once you have the right pane and it is a PathBasePaneTab
or alike you can do pane.pwd()
.
Does this point you into the right direction?
Basically youād need to get explicit as to which specific UI element of Houdini you want to take the current context from - since you might have multiple.
Thanks for the response.
This will sound stupid for asking this, so sorry in advance. But I canāt use the paneTabUnderCursor
or paneUnderCursor
.
It gives me an error of
missing 1 required positional argument: 'self'
I checked the documentation and it does not accept arguments. Iām guessing self
here needs to be implemented in a Class.
I tried that too like literraly
print (hou.Desktop.paneUnderCursor(self))
but it gives me another error of
TypeError: in method 'Desktop_paneUnderCursor', argument 1 of type 'HOM_Desktop *'
Itās a method on a class. The Desktop
class should first be instantiated as an instance - thatās why you are getting the error.
What that means in this case is that you will need to get the active desktop first with hou.ui.curDesktop
desktop = hou.ui.curDesktop()
desktop.paneUnderCursor()
There might also be multiple active desktops apparently, see hou.ui.desktops
.
Iām not behind a machine with Houdini currently - so not entirely sure this is the way to use it.
Ah gotcha. Thanks for sticking through me.
It now works as expected
Hereās the code I used for reference:
desktop = hou.ui.curDesktop()
pane = desktop.paneTabUnderCursor()
current_context = pane.pwd()
current_context.createNode('node_name')