Jump to content


Python: Checking if the content of a network changed


  • Please log in to reply
10 replies to this topic

#1 sanostol

sanostol

    Houdini Master

  • Members
  • PipPipPipPip
  • 647 posts
  • Joined: 09-January 06
  • Location:Munich, Germany
  • Name:Martin Matzeder

Posted 31 March 2012 - 12:02 AM

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, 31 March 2012 - 12:19 AM.

Martin Matzeder - Booyabase

#2 symek

symek

    Grand Master

  • Members
  • PipPipPipPipPip
  • 1,535 posts
  • Joined: 02-November 04
  • Location:Waw/Pol
  • Name:Szymon Kapeniak

Posted 31 March 2012 - 04:23 AM

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, 31 March 2012 - 05:30 AM.

(...) It was late, late in the evening, the lovers they were gone;
The clocks had ceased their chiming, and the deep river ran on.

#3 sanostol

sanostol

    Houdini Master

  • Members
  • PipPipPipPip
  • 647 posts
  • Joined: 09-January 06
  • Location:Munich, Germany
  • Name:Martin Matzeder

Posted 01 April 2012 - 02:16 AM

Hi SYmek,

View PostSYmek, on 31 March 2012 - 04:23 AM, said:

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

View PostSYmek, on 31 March 2012 - 04:23 AM, said:

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, 01 April 2012 - 02:16 AM.

Martin Matzeder - Booyabase

#4 sanostol

sanostol

    Houdini Master

  • Members
  • PipPipPipPip
  • 647 posts
  • Joined: 09-January 06
  • Location:Munich, Germany
  • Name:Martin Matzeder

Posted 01 April 2012 - 02:39 AM

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, 01 April 2012 - 02:46 AM.

Martin Matzeder - Booyabase

#5 symek

symek

    Grand Master

  • Members
  • PipPipPipPipPip
  • 1,535 posts
  • Joined: 02-November 04
  • Location:Waw/Pol
  • Name:Szymon Kapeniak

Posted 01 April 2012 - 03:27 AM

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...
(...) It was late, late in the evening, the lovers they were gone;
The clocks had ceased their chiming, and the deep river ran on.

#6 sanostol

sanostol

    Houdini Master

  • Members
  • PipPipPipPip
  • 647 posts
  • Joined: 09-January 06
  • Location:Munich, Germany
  • Name:Martin Matzeder

Posted 01 April 2012 - 09:55 AM

View PostSYmek, on 01 April 2012 - 03:27 AM, said:

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, 01 April 2012 - 09:55 AM.

Martin Matzeder - Booyabase

#7 rdg

rdg

    Houdini Master

  • Members
  • PipPipPipPip
  • 729 posts
  • Joined: 21-August 05
  • Location:weta
  • Name:Georg Duemlein

Posted 01 April 2012 - 12:43 PM

View Postsanostol, on 01 April 2012 - 09:55 AM, said:

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 :)
The Industrial Parametrization of the World
http://rdg.preset.de/

#8 symek

symek

    Grand Master

  • Members
  • PipPipPipPipPip
  • 1,535 posts
  • Joined: 02-November 04
  • Location:Waw/Pol
  • Name:Szymon Kapeniak

Posted 01 April 2012 - 12:51 PM

View Postrdg, on 01 April 2012 - 12:43 PM, said:

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 :)).
(...) It was late, late in the evening, the lovers they were gone;
The clocks had ceased their chiming, and the deep river ran on.

#9 graham

graham

    Houdini Master

  • Moderator
  • 666 posts
  • Joined: 13-September 06
  • Location:Santa Monica, CA
  • Name:Graham Thompson

Posted 01 April 2012 - 02:43 PM

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, 01 April 2012 - 02:44 PM.

I write python and break things.

#10 graham

graham

    Houdini Master

  • Moderator
  • 666 posts
  • Joined: 13-September 06
  • Location:Santa Monica, CA
  • Name:Graham Thompson

Posted 01 April 2012 - 03:55 PM

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, 01 April 2012 - 03:57 PM.

I write python and break things.

#11 sanostol

sanostol

    Houdini Master

  • Members
  • PipPipPipPip
  • 647 posts
  • Joined: 09-January 06
  • Location:Munich, Germany
  • Name:Martin Matzeder

Posted 06 April 2012 - 02:43 AM

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:
Martin Matzeder - Booyabase




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users