Jump to content

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


catchyid

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

Link to comment
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
Link to comment
Share on other sites

  • 3 years later...

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.

Link to comment
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")

Link to comment
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.

Link to comment
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

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