Jump to content

Python: Checking if the content of a network changed


sanostol

Recommended Posts

I'm working on a asset that needs to be updated if the user adds a node inside it, but there is only a python function for this if the input has changed. is there another way to do this?

another strang thing is that hou.pwd().children() gives me the child nodes, hou.pwd().parent() gives me NONE

any ideas?

Martin

Edited by sanostol
Link to comment
Share on other sites

Hi Martin,

As to the first question, you could register an event callback with: hou.Node.addEventCallback(), so you can react on ChildCreated event among many others.

Second issue sounds suspicious, is it a Obj HDA or SOP? From which place do you evaluate hou.pwd().parent()? It should work imho.

Edited by SYmek
Link to comment
Share on other sites

Hi SYmek,

Hi Martin,

As to the first question, you could register an event callback with: hou.Node.addEventCallback(), so you can react on

ChildCreated event among many others.

great I will try it, sounds very powerfull

Second issue sounds suspicious, is it a Obj HDA or SOP? From which place do you evaluate hou.pwd().parent()? It should work imho.

it is a subnetype for outputdrivers. mh, strange

and I evaluate it as script in the hda module, like this hou.pwd().parent()

thanks Martin

Edited by sanostol
Link to comment
Share on other sites

the eventCallback is very cool, but it does not show up anywhere, right? how can one inspect all types of events on a object?

and they don't get saved to the assets or in the scene so I have to create them by a script everytme the asset is loaded I guess

but for now it does it's job :)

Edited by sanostol
Link to comment
Share on other sites

Yes, I think you have to create event callbacks in On Created script. They are grouped as hou.nodeEventType.*

As to hou.pwd().parent() it works in ROP subnet hdaModule in 12.0.581 here, which is strange as I thought it won't. There used to be a limitation for hou.pwd() only for parameters calls. Must had changed at some point...

Link to comment
Share on other sites

As to hou.pwd().parent() it works in ROP subnet hdaModule in 12.0.581 here, which is strange as I thought it won't. There used to be a limitation for hou.pwd() only for parameters calls. Must had changed at some point...

very strange, hou.pwd().parent() gives me a None on 12.0.581 , but anyway it would have been a workaround, the event method is much better

thanks again for this

Martin

Edited by sanostol
Link to comment
Share on other sites

very strange, hou.pwd().parent() gives me a None on 12.0.581

Did you check what hou.pwd() in your case actually refers to?

In many cases hou.pwd() is hou.node('/obj') or some other top level node.

kwargs['node'] might be the one your looking for.

But this is just a wild guess :)

Link to comment
Share on other sites

Did you check what hou.pwd() in your case actually refers to?

In many cases hou.pwd() is hou.node('/obj') or some other top level node.

kwargs['node'] might be the one your looking for.

But this is just a wild guess :)

Georg has good intuitions (and wild!), but the parent of /rop/subnet is /rop and the parent of /rop is "/" which is also a node, and finally third parent in raw is None. Martin, did you look for a grand-grand-grand parent (because knowing our history, I'm telling you, he/she was Polish :)).

Link to comment
Share on other sites

I'm inclined to agree with Georg in that it something to do with how the code is called and what exactly you are doing. I should point out that using hou.pwd() inside a PythonModule is always a bad idea. Since the module is not tied to any particular instance of the node, you can get irregularities based on how things are called. If you could post an example file I'm sure it would be readily apparent what is going on.

Edited by graham
Link to comment
Share on other sites

Now that I have a moment, here's a bit more information/examples about how the current working director is set and what hou.pwd() will return in various instances.

Normally, unless you change it, it tends to stay at the root node '/'.

When evaluating event handlers such as OnInputChanged and OnNameChanged it will not change. In this case, it will generally be '/'.

When running an OnCreated script, the cwd will point to the parent of where the node is created. For example, when creating a Geometry object under '/obj', hou.pwd() will return /obj.

Inside of parameters or parameter callbacks, it will be changed to the node that parameters belong to. Since the majority of PythonModule use is usually for parameter callbacks, it's a fair bet that hou.pwd() inside a PythonModule will resolve to an instance of the node type the module belongs to. This also applies to the Pre/Post Render/Frame script parameters on ROP nodes.

Inside of the PythonCook (Code tab) of a Python operator the cwd will resolve to the instance of the operator that is cooking. hou.pwd() in the PythonModule when invoked from thsi method will resolve to the operator instance.

Node event callbacks will resolve to the cwd, not the node that has somehow changed.

Edited by graham
Link to comment
Share on other sites

I did a new run on this. the events give me dictionary object containing the node and the type of it. by picking up the node I can do .parent() without problem. maybe my problem was to try pwd from a event, a thing I think I forgot to mention :rolleyes:

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