<?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="abcprocess" label="ABC Process" icon="PLASMA_App">
    <script scriptType="python"><![CDATA[# select an abc archive
# make a new object with alembic archive name +_OUT

# only works on Alembic Archive Object
if hou.selectedNodes()[0].type() == hou.nodeType(hou.objNodeTypeCategory(), 'alembicarchive'):
    archive = hou.selectedNodes()[0]
#    print archive
else:
    raise hou.Error("Please select a Alembic Archive Object")

# get shape name
shape = ()
shape = hou.ui.readInput(
    message="Shape Name:",
    initial_contents = "_geoShape")
shape = shape[1]

# make archive_OUT node
network = archive.parent()
archive_out_name = archive.name() + '_OUT'
archive_pos = archive.position()
archive_out = network.createNode("geo", archive_out_name)
archive_out.move(hou.Vector2(archive_pos[0], archive_pos[1] - 1))

for child in archive_out.children():
    child.destroy()
    
objmerge = archive_out.createNode("object_merge", "object_merge_archive")
objmerge.parm("xformtype").set(1)
objmerge.setColor(hou.Color([0.302, 0.525, 0.114]))
archive_sop_out = archive_out.createNode("null", "OUT")
archive_sop_out.setFirstInput(objmerge)
archive_sop_out.setDisplayFlag(True)
archive_sop_out.setRenderFlag(True)
archive_sop_out.setColor(hou.Color([0.8, 0.016, 0.016]))
archive_sop_out.moveToGoodPosition()

# find all alembic nodes

paths = []
node = archive.recursiveGlob("*", hou.nodeTypeFilter.Sop)
#print node
nodes = []
for n in node:
    if n.type().name() == 'alembic':
        nodes.append(n)
#print nodes
numobj = len(nodes)
for n in nodes:
        n_parent = n.parent()
        n_name = n.name()
        # make a group node
        sop_group = n_parent.createNode("group", n_name + "_group")
        sop_group.setFirstInput(n)
        # make a null
        sop_out_null = n_parent.createNode("null", n_name + "_OUT")
        sop_out_null.setFirstInput(sop_group)
        # make an object merge
        sop_objmerge = n_parent.createNode("object_merge", "object_merge")
        sop_objmerge.parm("xformtype").set(1)
        sop_objmerge.parm("objpath1").set(archive_sop_out.path())
        sop_objmerge.parm("group1").set(sop_group.parm("crname").eval())
        # make a group delete
        sop_group_delete = n_parent.createNode("groupdelete", "groupdelete")
        sop_group_delete.parm("group1").set("*")
        sop_group_delete.setFirstInput(sop_objmerge)
        # make an attribute_delete
        sop_attrib_delete = n_parent.createNode("attribdelete", "attribdelete")
        sop_attrib_delete.setFirstInput(sop_group_delete)

        # change name
        n.setName(n_name + '_ORIG')

        # make out NULL with original name
        out_null = n_parent.createNode("null", n_name)
        out_null.setFirstInput(sop_attrib_delete)
        out_null.setDisplayFlag(True)
        out_null.setRenderFlag(True)


        path = archive.path() + "/" + archive.relativePathTo(out_null) + "_OUT"

        paths.append(path)

        n_parent.layoutChildren()

objmerge.parm("numobj").set(numobj)

for num, objpath in enumerate(paths, 1):
        objmerge.parm("objpath"+str(num)).set(objpath)













]]></script>
  </tool>
</shelfDocument>
