Jump to content

export python code for OnCreated.py


tagosaku

Recommended Posts

Hi, I am studying how to make OnCreated.py by exporting codes with asCode. So far, I understood a procedure:

1 Create a new folder and create some parameters inside of the folder in edit parameter interface on a node.

2 Use findFolder() to take a new folder tab, and write out a python code with as Code. 

3 Create actual a xxx_OnCreated.py that either imports or copy&paste the #2 written code.

 

Questions are :

1 Can we export multi folder tabs at once as one master code? 

2 Can we export expressions existing in a default parameter AND new folder tabs together, instead of separately? (I know I can manually add this code into OnCreated.py later.. )

I think a problem is that, if we export all folders and parameters including default param&folders,  onCreated.py will get error due to the default one including. That makes this procedures difficult.  

 

# export new folder and its parameters. Let's say exportTab.py

node = hou.node("/out/geometry1")

ptg = node.parmTemplateGroup()
folder = ptg.findFolder("NewFolder1")

with open('f:/exportTab.py','w') as f:
  f.write( folder.asCode(function_name='createTab') )
  
##  Questions are 
##  I want to export NewFolder1 and NewFolder2 and NewFolder3 together and do f.write
##  I want to export an expression together, for instance, "/obj/geo1/out_render" in Geometry1 > SOP Path param here, and do f.write.
##  I could manually paste later like a  node.parm('soppath').set('/obj/geo1/out_render')  but ideally export together here..
#Then Let's say this is , Geoemetry_OnCreated.py, and try to attach the exported folder tab and parameters 

import exportTab


node = kwargs['node']


ptg = node.parmTemplateGroup()

defaultFolder = hou.FolderParmTemplate('default', 'Default', parm_templates=ptg.entriesWithoutFolders())
for p in ptg.entriesWithoutFolders():
    ptg.remove(p)

ptg.append(defaultFolder)


ht = exportTab.createTab()
ptg.append(ht)


node.setParmTemplateGroup(ptg)

image.thumb.png.26c980654da4ece0940184bff6fa31e3.png

Maybe my explanation is confusing, but I hope the code and screenshot help to show what I try to do. 
In other words, in conclusion, with the screenshot, how to export multi tabs&param (#1) and expression(#2:sorry it's empty,,) ?

Thanks!

 

 

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