Jump to content

Calling callback script with stamp ?


nmn

Recommended Posts

Hi everyone,

I hope someone has an answer to this question,

let us say I have a spare parameter on an asset which, whenever modified, calls a script inside the python module of that asset,

everything works great until the moment where I want to create multiple copies of this asset using a copy SOP,

and using stamping to set that parameter values from my copy SOP, in this case the callback script is not called ...

so any solution to that problem ?

Cheers

Link to comment
Share on other sites

Unfortunately callbacks do not work that way. They only respond to changes made through the UI, opparm -C or hou.Parm.pressButton(). Even if you put $F in a field with a callback you will notice it does not run your callback as the frame number changes.

However, what you should be able to do is rather than rely on the callback to run your code, just call that code from within the parameter for each stamp value. For example, the following code gets run for me on a per stamp basis.

val = hou.pwd().node("../copy1").stampValue("cpy", 0)
hou.pwd().hdaModule().myCallback(hou.pwd(), val)
return val

This example gets the stamp value, calls the callback function itself, passing in the changed value, or however you have it set up, then returns the value of the stamp value to the parameter, thus behaving like a normal stamp but explicitly calling your function each stamp instance.

Edited by graham
Link to comment
Share on other sites

Hi graham,

thanks for your answer,

though I did many tests and sadly it doesn't seem to work for me ...

is it possible that you post a scene file example ?

Thanks in advance

Unfortunately callbacks do not work that way. They only respond to changes made through the UI, opparm -C or hou.Parm.pressButton(). Even if you put $F in a field with a callback you will notice it does not run your callback as the frame number changes.

However, what you should be able to do is rather than rely on the callback to run your code, just call that code from within the parameter for each stamp value. For example, the following code gets run for me on a per stamp basis.

val = hou.pwd().node("../copy1").stampValue("cpy", 0)
hou.pwd().hdaModule().myCallback(hou.pwd(), val)
return val

This example gets the stamp value, calls the callback function itself, passing in the changed value, or however you have it set up, then returns the value of the stamp value to the parameter, thus behaving like a normal stamp but explicitly calling your function each stamp instance.

Link to comment
Share on other sites

One thing I forgot to mention is that your parameter on your asset really needs to be referenced by something inside your asset so that it actually gets evaluated each time the network cooks.

In the attached file I have a sphere with its radx parm linked to my parameter on the asset. When the Copy cooks you should see lots of printing of things in your console. If you remove this channel reference so nothing references that parameter it isn't going to be cooked each stamp, only the geometry inside the asset.

You can also do this by adding a node specific event callback (new in Houdini 11). http://www.sidefx.com/docs/houdini11.0/hom/hou/Node#addEventCallback

This callback function gets called whenever the parameter changes. In this case you could just have the parameter set to the regular stamp() function and rely on this method to run the code. However this method also requires that this parameter be reference by something that is required to cook each time.

If your parameter is not actually linked to something the only way to get the result you want is to link something to it but you can sort of hack it. If you just grab a parameter on a node somewhere and put a channel reference to the asset parm, but also return the value you want it will cause it to cook properly.

ch("../myparm")
return 1

Throwing this in the radx parm for example causes the above parm to cook, thus calling your script each time, while still returning the radius of 1 each time.

It might not be ideal but it is the only way to ensure your asset parameter cooks every copy attempt.

stamp_call_function.hip

Link to comment
Share on other sites

Hi graham, and thank you very much for your help,

indeed that works, but it doesn't at all times ...

just try the following scenario, open the file you've posted,

and try changing the grid columns for example (by typing values in, not using the slider),

to change the number of points to generate more or less copies ...

sometimes the callback is called and some other times, it's not called at all :|

Regards

Edited by nmn
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...