Jump to content

Does anyone know why my Callback script is not working?


RustyMac2020

Recommended Posts

Hi all; I seem to be having a strange issue where I create a button on a null that is suppose to be a control system for a paint node; however, the button does not select the paint node. I have tried to use callback scripts by using a function like hou.cd("../path to the node") however I'm not getting any results and the button is not activating I'm not sure what is happening?. I appreciate all help anyone has to offer & I'm going to link the file that is isolating the issue underneath if anyone would like to take a look at it  thanks.

 

 

Kind Regards

Rusty.M 

A simplified HIP file version of the same issue: cd_Button.hipnc

InvalidPath_Issue.png

My_Callback_Script_location.png

Edited by RustyMac2020
Link to comment
Share on other sites

hou.cd() is basically only for changing the sessions's working directory and doesn't do much in terms of anything interactive stuff.  If you are wanting to just select that other node you just need to call hou.Node.setSelected

In your example file I'd do something like the following to set that node selected (and the only selected node)

hou.pwd().node("../paint").setSelected(True, True)

 

  • Thanks 1
Link to comment
Share on other sites

On 28/04/2020 at 10:29 PM, graham said:

hou.cd() is basically only for changing the sessions's working directory and doesn't do much in terms of anything interactive stuff.  If you are wanting to just select that other node you just need to call hou.Node.setSelected

In your example file I'd do something like the following to set that node selected (and the only selected node)


hou.pwd().node("../paint").setSelected(True, True)

 

Wow! thank you so much for the help :D really appreciated

Link to comment
Share on other sites

On 28/04/2020 at 10:29 PM, graham said:

hou.cd() is basically only for changing the sessions's working directory and doesn't do much in terms of anything interactive stuff.  If you are wanting to just select that other node you just need to call hou.Node.setSelected

In your example file I'd do something like the following to set that node selected (and the only selected node)


hou.pwd().node("../paint").setSelected(True, True)

 

Hey; so why does this happen then? wouldn't the hou.cd alone change the current working directory? and why does Houdini require the Present Working Directory? is this like getting the software to ask questions? for example which directory are we in currently? then what node can we see?... now select that node? would this be how a programmer or coder would think about it? 

 

Because I understand the concept of going through files and have done some shell script before & windows cmd; however I am still trying to learn to think like a coder/programmer in order to learn new skills. 

Kind Regards 

Rusty.M  

Link to comment
Share on other sites

The pwd/cwd basically is what Houdini will use when trying to evaluate things with relative references.  Something like ch("../foo") only really has meaning when it's evaluated from a certain location that has a channel called 'foo' one level up.  Changing the cwd merely changes where things that rely on relative references are based.  Usually this doesn't really matter much since parameters and such are always evaluated with the cwd being their node, regardless of where the global cwd is set.

In this case it's pretty common to just use hou.pwd() inside a callback script or menu script since it's the easiest way to get at the node which the parameter belongs to.  You can also use the kwargs dict which contains the node as well as other things if you need more information than that.

kwargs["node"].node("../paint").setSelected(True, True)

 

In terms of what code code is doing it's getting the current node the callback is happeing for, finding a sibling node called "paint" which is the one that we want to be selected, then setting it to be selected and clearing the existing selection since we only want it to be selected.  Alternatively you could also use hou.clearAllSelected() and then select the node, omitting the second arg all together.

hou.clearAllSelected(); kwargs["node"].node("../paint").setSelected(True)

 

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...