Jump to content
catchyid

How to know the name the instance of the asset that OnCreated() is associated with?

Recommended Posts

Hi,

When I create a digital asset, I go to Scripts->OnCreated() method and write some python script to change some parameters in the newly created digital asset, HOWEVER, I don't know the name of the asset, hence I don't know the path to any node inside the digital asset? When I type hou.pwd(), I get "obj"...

Thanks,

onCreated.hip

onCreated.png

Share this post


Link to post
Share on other sites

There is Node and NodeType objects in kwargs dictionary available:

# Available kwargs contents:
print(kwargs)

# Node's name like 'test12':
kwargs['node'].name()

# Set parameter:
kwargs['node'].parm('foo').set('123')

# Set parameter on node inside subnet:
kwargs['node'].node('inside1').parm('foo').set('123')

 

Edited by f1480187
  • Like 1

Share this post


Link to post
Share on other sites

hi guys,

I'd need to get one step further with this and read the variables produced in OnCreated script by different scripts in the same HDA (Python Module).

Spent a day reading through Houdini docs but can't figure out how to do that.

help appreciated.

D.

Share this post


Link to post
Share on other sites
4 hours ago, davpe said:

hi guys,

I'd need to get one step further with this and read the variables produced in OnCreated script by different scripts in the same HDA (Python Module).

Spent a day reading through Houdini docs but can't figure out how to do that.

help appreciated.

D.

Depending on what you mean by "variables". They can be

1. Environment variables (os.environ),

2. Hip variables (stored in hip): hou.hscript("set -g VAR={}".format(value))

3. Session variables: hou.session.VAR = "FOO"

4. You can store data on the node: hou.Node.setUserData("VAR", "FOO") and read it back with hou.Node.userData("VAR")

Share this post


Link to post
Share on other sites

no sorry, I meant like this, for instance:

1. in OnCreate:

path = hou.pwd().path()

2. in PythonModule i want to access this path string.

this is a trivial example, I'm just looking for a general way to exchange data between HDA scripts triggered on different events - if it makes sense.

Share this post


Link to post
Share on other sites

I'm not sure you can pass python variables like that as those are separate scopes and I'd avoid using global variables

however you can store data on the instance itself and then retrieve at any time using setUserData() or setCachedUserData() if you don't need them to persist after you close the session

https://www.sidefx.com/docs/houdini/hom/hou/Node.html#setUserData

Share this post


Link to post
Share on other sites

thanks anim, user data thing sounds promissing. will look into that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×