I can give you my piece of code to create a shrinkWrap, I don't have maya so can't really check your code :
def getTargetMesh(targetTrans=str):
sh = cmds.ls(targetTrans, dag=True, shapes=True)
# Find if at least one of them is an allowable target type
for s in sh:
io = cmds.getAttr(s+".io")
if io:
continue
mtype = cmds.nodeType(s)
if mtype == "mesh":
return s
return None
def shrinkWrap(mesh, target, **kwargs):
targetMesh = getTargetMesh(target) # find a not intermediate shape
# Find all the surf transforms that have been selected
surf = cmds.listRelatives(mesh, path=True)
surface = surf[0]
# SET A BUNCH OF ATTRIBUTES WITH KWARGS or with default value
projection = kwargs.get('projection') or 0
closestIfNoIntersection = kwargs.get('closestIfNoIntersection') or 0
reverse = kwargs.get('reverse') or 0
bidirectional = kwargs.get('bidirectional') or 0
boundingBoxCenter = kwargs.get('boundingBoxCenter') or 1
axisReference = kwargs.get('axisReference') or 0
alongX = kwargs.get('alongX') or 0
alongY = kwargs.get('alongY') or 0
alongZ = kwargs.get('alongZ') or 0
offset = kwargs.get('offset') or 0
targetInflation = kwargs.get('targetInflation') or 0
shrinkwrapNode = cmds.deformer(surface, type='shrinkWrap')[0]
cmds.setAttr(shrinkwrapNode + ".projection", projection)
cmds.setAttr(shrinkwrapNode + ".closestIfNoIntersection", closestIfNoIntersection)
cmds.setAttr(shrinkwrapNode + ".reverse", reverse)
cmds.setAttr(shrinkwrapNode + ".bidirectional", bidirectional)
cmds.setAttr(shrinkwrapNode + ".boundingBoxCenter", boundingBoxCenter)
cmds.setAttr(shrinkwrapNode + ".axisReference", axisReference)
cmds.setAttr(shrinkwrapNode + ".alongX", alongX)
cmds.setAttr(shrinkwrapNode + ".alongY", alongY)
cmds.setAttr(shrinkwrapNode + ".alongZ", alongZ)
cmds.setAttr(shrinkwrapNode + ".offset", offset)
cmds.setAttr(shrinkwrapNode + ".targetInflation", targetInflation)
# Add the target object
#
cmds.connectAttr(targetMesh + ".w", shrinkwrapNode + ".tgt")
# connect up the smooth target attributes
# so the smoothed target follows the target shape's settings
#
cmds.connectAttr(targetMesh + ".co", shrinkwrapNode + ".co")
cmds.connectAttr(targetMesh + ".suv", shrinkwrapNode + ".suv")
cmds.connectAttr(targetMesh + ".kb", shrinkwrapNode + ".kb")
cmds.connectAttr(targetMesh + ".bnr", shrinkwrapNode + ".bnr")
cmds.connectAttr(targetMesh + ".khe", shrinkwrapNode + ".khe")
cmds.connectAttr(targetMesh + ".peh", shrinkwrapNode + ".peh")
cmds.connectAttr(targetMesh + ".kmb", shrinkwrapNode + ".kmb")
cmds.select(clear=True)
return shrinkwrapNode
Here is a function where im using it to output a sphere with only quads
def createSquareSphere(res=4):
cub = cmds.polyCube(n = 'qSphere#')
v = round(sqrt(pow(4, res)))*2
sph = cmds.polySphere(n = 'proj_tmp', sa=v, sh=v)
cmds.polySmooth(cub, dv = 4, mth = 0, sdt = 2, ovb = 1, ofb = 3, ofc = 0, ost = 0, ocr = 0, bnr = 1,
c = 1, kb = 1, ksb = 1, khe = 0, kt = 1, kmb = 1, suv = 1, peh = 0, sl = 1,
dpe = 1, ps = 0.1, ro = 1, ch = 1)
shWrp = shrinkWrap(cub[0], sph[0], projection = 3, reverse = 1)
cmds.delete(cub, ch = True)
cmds.delete(sph)
return cub[0]