There are 3 simple cases of copying. You want to copy the node, and just the node with input values but without inheriting connections. Secondly you want to copy the inbound graph fully. Last trivial option is to want to copy node with same connections.
What you want is combination of second and third option. This is not trivial as you have no ESP attachment to your computer. But this is what you do:
- You disconnect blendshape targets form the blendhsape, storing the connected port names.
- copy all with full network
- reconnect the blendshapes disconnected.
Quick code of above, select object to copy (not tested not production ready, use at your own risk):
# licence cc sa, by - joojaa 2013
import maya.cmds as cmds
def chunk2(data):
it=iter(data)
data=[]
for a, b in list(zip(it, it)):
a = '.'+a.split('.',1)[1]
data.append( (a, b) )
return data
def disconnect(connections, obj):
for destination, source in connections:
cmds.disconnectAttr(source, obj + destination)
def reconnect(connections, obj):
for destination, source in connections:
cmds.connectAttr(source, obj + destination)
def getBlend(selection):
shape = cmds.ls(selection, dag=1, shapes=1)[0]
return cmds.ls(cmds.listHistory(shape),type='blendShape')[0]
def duplicate_blends_with_same_inbound_shapes(howmany):
sel = cmds.ls(sl=1)
blend = getBlend(sel)
conns = chunk2(
cmds.listConnections(blend+'.inputTarget',
d=1, s=1, p=1, c=1)
)
disconnect(conns, blend )
for _ in range(howmany):
dup=cmds.duplicate(sel, inputConnections=1)
reconnect(conns, getBlend(dup))
reconnect(conns, blend)
#usage example make 2 copies
duplicate_blends_with_same_inbound_shapes(2)