Skip to content

Instantly share code, notes, and snippets.

@hmasato
Last active May 16, 2016 15:08
Show Gist options
  • Save hmasato/996e5d40542937b1f5e4 to your computer and use it in GitHub Desktop.
Save hmasato/996e5d40542937b1f5e4 to your computer and use it in GitHub Desktop.
[houdini, python] Paste Copied (Rel/Abs) References for stamp()
#hmasato
#https://gist.github.com/hmasato/996e5d40542937b1f5e4
#PARMmenu.xml
"""
<?xml version="1.0" encoding="UTF-8"?>
<menuDocument>
<menu>
<scriptItem id="my_pasteRefAsStamp">
<label>* Paste References [stamp]</label>
<insertBefore>paste_channels</insertBefore>
<scriptPath>$HOME/houdini14.0/scripts/my_pasteParamsAsStamp.py</scriptPath>
<scriptArgs>absolute</scriptArgs>
</scriptItem>
<scriptItem id="my_pasteRelRefAsStamp">
<label>* Paste Relative References [stamp]</label>
<insertBefore>paste_channels</insertBefore>
<scriptPath>$HOME/houdini14.0/scripts/my_pasteParamsAsStamp.py</scriptPath>
<scriptArgs>relative</scriptArgs>
</scriptItem>
</menu>
</menuDocument>
"""
#
# pasteParamsAsStamp
#
# ch() => stamp()
#* Paste Copied Relative References
#* Paste Copied References
#
import sys
def _main(dstList=[], opts=[]):
relative = not ("absolute" in opts)
cbList = hou.parmClipboardContents()
if len(cbList) < 1:
hou.ui.displayMessage(u'Nothing has been copied.')
idxList = range(len(cbList))
if len(idxList) == 1: idxList = [0] * len(dstList)
num = min(len(idxList), len(dstList))
for i in xrange(num):
cb = cbList[idxList[i]]
(src, dst) = (hou.parm(cb['path']), dstList[i])
srcName = src.name()
#for Copy, ForEach, etc
if src.parmTemplate().dataType() == hou.parmData.String:
srcName = cb['value']
srcPath = src.node().path()
if relative: srcPath = dst.node().relativePathTo(src.node())
dstValue = dst.eval()
if dst.parmTemplate().dataType() == hou.parmData.String:
dstValue = '"%s"' % dstValue
dst.setExpression('stamp("%s", "%s", %s)' % (srcPath, srcName, dstValue))
_main(kwargs.get('parms', []), sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment