Search - User list
Full Version: Extract embedded files from HDA
Root » Technical Discussion » Extract embedded files from HDA
9krausec
How would one go about extracting an embedded image file in an HDA? Is this possible? I've been trying to find edu material about this online but there doesn't seem to be too much of any documentation on this (that I could find).

Thank you for any help!
goldfarb
if you mean saving a file from the Extra Files area then you can select the file in the list, and at the bottom right of the Type Properties dialog > Save as File
9krausec
goldfarb
if you mean saving a file from the Extra Files area then you can select the file in the list, and at the bottom right of the Type Properties dialog > Save as File


Any idea how to do that through HOM - Python by chance? I'm trying to query a list of internal HDA files and if those files are images I wanted to extract them out of the HDA using Python.

Having a hard time finding documentation on how to handle an operation like this (at least where I've been looking for the information).

Thank you for the reply.
jsmack
You may find these classes useful now, and in the future when scripting with HDA.

http://www.sidefx.com/docs/houdini/hom/hou/HDADefinition.html [www.sidefx.com]
http://www.sidefx.com/docs/houdini/hom/hou/HDASection.html [www.sidefx.com]
9krausec
Thank you. I'll keep on trying, but I'm still having some issues getting my head around this. For instance-

t = hou.node('/obj/customHDA')
#t has section 'kittens.jpg' in it

t.type().definition().hasSection("kittens.jpg")
#Returns True

for x in t.type().definitions.section():
     print x
     #returns the section name as a string

So in the above, I can ask if a section exists. I can return a names of sections a strings… But I'm having a hard time figuring out how to return a section object and work on it. Even if I figured out how to return a section object, I'm not finding any “write out contents of section” in the section documentation.

I'm also confused why there is a “definition()” method inside of the HDASection class as would the the HDASection be inside of a definition?

EDIT: I'll also be happy to take any suggested learning resources on this too if there are any recommendations. Docs only make so much sense to me without seeing the application.
jsmack
The HDASection page has an example function of how to write out the contents to disk.

I can't speak for the devs, but I can see wanting to be able to pass a section to a function or other object without having to also pass the definition to which it belongs.
9krausec
Alright, I'm slowly figuring this out with all of your help. I was a bit confused on the syntax of it all, but here is what I have going so far… “saveSectionToFile” is from the docs..

def saveSectionToFile(section, file_name):
    '''Given a section, save it to a file.'''
    section_file = file(file_name, "w")
    section_file.write(section.contents())
    section_file.close()

t = hou.node('/obj/hdaObj')
td = t.type().definition()
if td.hasSection('kittens.jpg'):
	saveSectionToFile(td.sections().get('kittens.jpg'), 'C:/Users/clayton.krause/
Desktop/tmp/kittens.jpg')


Attached is the original jpg as well as the extracted. The original comes in at 50.6 KB, the extracted at 50.8 KB. The original isn't opening up as a jpg picture file should open up.

If anyone would mind explaining to me why the extracted jpg picture isn't opening up, that would help out a lot. I tried all the 3 compression types without any success-

Gzip
Blosc
NoCompression

Thank you all for any help in getting me to understand this better.

EDIT: I'd like to add that Photoshop posts with the following warning message when attempting to open the kittensExtracted.jpg

“Could not complete your request because an invalid DQT JPEG segment QTable number is found (it must be < 4)”
goldfarb
you'll need to use Binary:
section_file = file(file_name, "wb")
9krausec
goldfarb
you'll need to use Binary:
section_file = file(file_name, "wb")

Thank you for that! I wouldn't of picked up on that being the issue for a long while…

Alright gang, thank you for all the help! I try to ask stupid beginner questions sparingly and look through the docs / research before asking as best as I can! I'm just getting familiar with HOM coming from an intermediate Python background (I say intermediate because I've used a lambda function before, lawl).

Anyways, thank you for your time! Appreciate all the help here.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB