python - script to edit python module within HDA

   959   1   0
User Avatar
Member
39 posts
Joined: Nov. 2014
Offline
Hiya

I'm looking to have a python script go into my HDA and insert lines of code within the Scripts -> PythonModule section. Is it possible to access this via python? To answer the "why would you even want to do this?" questions, i'm trying to automate a larger more complicated process which requires code within the HDA to be present.
I've been looking at hou.HDADefinition as well as hou.hda which came close as you're able to set callbacks but that's been the closest i've seen thus far.

Thanks
User Avatar
Member
39 posts
Joined: Nov. 2014
Offline
took a day and a half to find this but here's the answer for others looking


import hou

node = hou.selectedNodes()[0] #get node

nodeTypeData= node.type().definition().sections()#dict of available info from the hda sections.
pycode = node.type().definition().sections()["PythonModule"].contents() #this gets the contents on the python module

node.type().definition().addSection("PythonModule","Test string goes here")#overwrite the python module here. you can use a file read in place of the string. 
Edited by wjm - July 21, 2022 08:47:09
  • Quick Links