Write(Modify) Extra File in HDAs

   4946   4   0
User Avatar
Member
6 posts
Joined: March 2015
Offline
Hi, there.
I have some HDAs that use an external python module. I'd like to package the module into the HDAs so that external files are not necessary to use them.
Currently I am embedding the python module using the “Custom Script” event handler, and I want to read file from “Extra Files” Tab.

- I find some methods from hou module.

About File Input:
hou.readFile(filepath)
hou.loadIndexDataFromFile(filepath)

this function works perfectly even though filepath is
filepath = "opdef:/Sop/HDA_Name?Extra_filename.txt"


But for file output functions it occurs error if filepath were HDA's path(“opdef:…”)
About File Output:
hou.saveIndexDataFromFile(filepath, dict)


This Code works : filepath is not HDA's Extra File's path
hou.saveIndexDataFromFile("D:/foo.txt", {"a" : "1"})

But this code doesn't works : filepath is HDA's Extra File's path
hou.saveIndexDataFromFile("opdef:/Sop/HDA_Name?Extra_filename.txt", dict)


Error Message:
File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.480/houdini/python2.7libs\hou.py", line 46239, in saveIndexDataToFile
    return _hou.saveIndexDataToFile(*args)
OperationFailed: The attempted operation failed.
Could not write to file

I try to find out solutions. In $HFS/…, hou.py file is hided to _hou.pyd(Python script made as a Windows DLL)…

How could I wrtie HDA's Extra Files in HDAs using python?

Could I know How
opdef:/Sop/HDA_Name?Extra_filename.txt
paths converted?
If I know this, I could use python's open method.

Thanks!
Hyunjun
Edited by Hyunjun Cheong - Jan. 3, 2017 00:29:55
User Avatar
Member
333 posts
Joined: Oct. 2012
Offline
Not sure why you would want to do that?

Any Reason to not just load and save the data in a invisible parameter on your HDA?
User Avatar
Member
6 posts
Joined: March 2015
Offline
Doudini
Not sure why you would want to do that?

Any Reason to not just load and save the data in a invisible parameter on your HDA?

Thanks Doudini

I want to write & read files from HDA's Extra Files Tab.

Because I don't want to write & read files from External Directory.

If I changed computer, I should move not only HDA asset but related External Files.

I want to embed all files related to HDA.

The Extra File is just txt file or json file.
Edited by Hyunjun Cheong - Jan. 3, 2017 00:29:23
User Avatar
Member
7714 posts
Joined: July 2005
Offline
Hyunjun Cheong
But this code doesn't works : filepath is HDA's Extra File's path
hou.saveIndexDataFromFile("opdef:/Sop/HDA_Name?Extra_filename.txt", dict)

I assume you actually meant saveIndexDataToFile() here instead. In anycase, opdef: paths not not usually writable. Your best chance is probably to hack around the sections of the hou.HDADefinition [sidefx.com] itself and then save it.
User Avatar
Member
6 posts
Joined: March 2015
Offline
edward
I assume you actually meant saveIndexDataToFile() here instead. In anycase, opdef: paths not not usually writable. Your best chance is probably to hack around the sections of the hou.HDADefinition [sidefx.com] itself and then save it.

Thanks, edward.

I look around all HDADefinition methods all yesterday.
For example,
...
...
------------------------------------------------------------------------
# HDA's Help Tab
node = hou.node("../HDANAME").type().definition().embeddedHelp()
------------------------------------------------------------------------
""" HDA's ExtraFileOptions -> Cursor of Extra Files, Extra Files's Name,
                      IsScipt, IsPython, Extra File's Source Path
"""
node = hou.node("../HDANAME").type().definition().extraFileOptions()
------------------------------------------------------------------------
""" HDA's sections -> return dict data type
{ 
'EXTRA_FILE_NAME' : 
<hou.HDASection EXTRA_FILE_NAME in definition of Sop HDA's Name in HDA's Installed Path>
}
"""
node = hou.node(".").type().definition().sections()
------------------------------------------------------------------------
# HDA's Name in HDA's Installed Path
node = hou.node(".").type().definition().libraryFilePath()
------------------------------------------------------------------------
# HDA's Name in HDA's User Info
node = hou.node(".").type().definition().userInfo()
------------------------------------------------------------------------
....
------------------------------------------------------------------------
....
------------------------------------------------------------------------
I look around HDASection [sidefx.com], too.

For example,
add SectionFromFile like other Extra Files File
class EXAMPLE():
    ....
    def addSectionFromFile(self, hda_definition, section_name, file_name):
        section_file = open(file_name, "r")
        hda_definition.addSection(section_name, section_file.read())
        section_file.close()
    
    def markSectionAsTxt(self, hda_definition, section_name):
        ....
        hda_definition.setExtraFileOption(section_name + "/IsPython", False)
        hda_definition.setExtraFileOption(section_name + "/IsScript", False)
        ....
    def ADD_MARK_SECTION(self):
        hda_definition = hou.node(".").type().definition()
        self.addSectionFromFile(hda_definition, "a.txt", hda_definition.libraryFilePath())
        self.markSectionAsTxt(hda_definition, "a.txt")
    ....

I run ADD_MARK_SECTION method.

The Section's Created like others. And, Extra File Option is added like others.
In Extra File's Tab “a.txt” is added!!

So, I can make Extra File's. I can see “a.txt” in Extra File's Tab.
But the content of “a.txt” said “Contains binary information”(Section Size always 487 bytes)
I don't know why.. (hou.readFile function cannot read “a.txt”)

And I think .hda file format is Oracle HyperData File [docs.oracle.com].(If not, let me know)
I open the .hda by Oracle's HDA. But HDA just contains definitions of shelves, toolbars, and tools. It should not be hand-edited when it is being used by the application. Note, that two definitions of the same element are not allowed in a single file. (<- This is message of HDA raw file) So, Editing .hda raw file is not good way.
And, .otl's raw file can be opened by Python's file open function. But .hda's raw file cannot.

Next I will try : modify or add the content of “a.txt”
I look around
$HFS/toolkit/include/HOM/HOM_hda.h
/HOM_HDADefinition.h
/HOM_HDASection.h
/...
/...
Edited by Hyunjun Cheong - Jan. 3, 2017 00:58:22
  • Quick Links