I am trying to change some HDA definitions through HOM. Once I get to the Tools.shelf section, I need to start parsing xml. Unfortunately I am not having much success using ElementTree. When I just get the section, convert it to a tree and back I loose information that makes the section unusable for houdini:
if s == “Tools.shelf”:
print definition.sections()
# convert the tools section to an xml tree
import elementtree.ElementTree
tree = elementtree.ElementTree.XML(definition.sections().contents())
# write the new element tree to the section
definition.sections().setContents(elementtree.ElementTree.tostring(tree))
print “—new—”
print definition.sections().contents()
outputs:
<?xml version=“1.0” encoding=“UTF-8”?>
<shelfDocument>
<!– This file 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. –>
<tool name=“$HDA_TABLE_$HDA_NAME” label=“$HDA_LABEL” icon=“SOP_subnet”>
<toolMenuContext name=“viewer”>
<contextNetType>SOP</contextNetType>
</toolMenuContext>
<toolMenuContext name=“pop_viewer”>
<contextNetType>SOP</contextNetType>
</toolMenuContext>
<toolMenuContext name=“network”>
<contextOpType>$HDA_TABLE/$HDA_NAME</contextOpType>
</toolMenuContext>
<toolSubmenu>Digital Assets</toolSubmenu>
<script scriptType=“python”><![CDATA[import soptoolutils
soptoolutils.genericTool(kwargs, ‘$HDA_NAME’)]]></script>
</tool>
</shelfDocument>
—new—
<shelfDocument>
<tool icon=“SOP_subnet” label=“$HDA_LABEL” name=“$HDA_TABLE_$HDA_NAME”>
<toolMenuContext name=“viewer”>
<contextNetType>SOP</contextNetType>
</toolMenuContext>
<toolMenuContext name=“pop_viewer”>
<contextNetType>SOP</contextNetType>
</toolMenuContext>
<toolMenuContext name=“network”>
<contextOpType>$HDA_TABLE/$HDA_NAME</contextOpType>
</toolMenuContext>
<toolSubmenu>Digital Assets</toolSubmenu>
<script scriptType=“python”>import soptoolutils
soptoolutils.genericTool(kwargs, ‘$HDA_NAME’)</script>
</tool>
</shelfDocument>
I have lost the xmlversion line and the warning.
Are there any tools in HOM to help me setting the tool options?
Any help is appreciated.
Koen

