1

So I've been playing around with for loops in Maya: but I've run into a peculiar error: after I try to run my script apparently an error appears in line 72 saying "// Error: No object matches name" I dont get it. I'm not asking for an object, I dont know why it's looking for an object. This is the script:

'''
import DS_spineOmatic_ribbonV1
reload (DS_spineOmatic_ribbonV1)
DS_spineOmatic_ribbonV1.gui()
'''

import re
import maya.cmds as cmds
import maya.mel as mel

if cmds.window("spineWin", exists =True):
    cmds.deleteUI("spineWin", window = True)

myWindow = cmds.window("spineWin",t='DS_spineOmatic_V1',w=200, h=500, toolbox=True)
column = cmds.columnLayout(adj=True)

'''
To DO:
    -You're going to have a series of scrips splitting into an IKFK spine and a ribon spine: this script will build the ribbon spine
'''

def gui():

    cmds.button( label="Generate Spine Proxy Locators", c = buildProxies)
    cmds.separator( w=200, h=3)
    cmds.button( label="Build Spine Joints", c = buildRibbon)
    cmds.separator( w=200, h=9)

    cmds.setParent('..')
    cmds.showWindow(myWindow)

def buildProxies(*args):
    locAmount = 2
    for i in range(locAmount):
        countLoc = i+1
        spaceLoc = cmds.spaceLocator(n = 'spineLoc_{}_PRX'.format(countLoc), p = [0,i*2.5,0])
        cmds.makeIdentity(spaceLoc, a=1, t=1)
        mel.eval('CenterPivot;')

    #create spine control curves
    cmds.curve(n='upLoftTemp', d=1,p=[(-1,0,0),(1,0,0)])
    cmds.curve(n='dwnLoftTemp', d=1,p=[(-1,0,0),(1,0,0)])
    cmds.curve(n = 'torso_CTRL', d=1, p=[(-2,0,0.7),(-2,0,1.4),(-3.3,0,0),(-2,0,-1.4),(-2,0,-0.7),(-1,0,-1),(-0.7,0,-2),(-1.4,0,-2),(0,0,-3.3),(1.4,0,-2),(0.7,0,-2),(1,0,-1),(2,0,-0.7),(2,0,-1.4),(3.3,0,0),(2,0,1.4),(2,0,0.7),(1,0,1),(0.7,0,2),(1.4,0,2),(0,0,3.3),(-1.4,0,2),(-0.7,0,2),(-1,0,1),(-2,0,0.7),(-2,0,1.4)])
    cmds.parent('spineLoc_2_PRX','spineLoc_1_PRX')
    #change following line to make duplicates of the spine when you figure out the spine joint linkup
    cmds.select(cl=True)
    cmds.joint(n='spine_bound1')


def buildRibbon(*args):

    cmds.select(cl=True) #this line clears your selection

    #create the ribbon
    cmds.pointConstraint('spineLoc_2_PRX','upLoftTemp',mo=False)
    cmds.pointConstraint('spineLoc_1_PRX','dwnLoftTemp',mo=False)
    cmds.loft('upLoftTemp','dwnLoftTemp',ch=False)
    cmds.rename('loftedSurface1','spineRibbon_loftSurface')
    cmds.rebuildSurface('spineRibbon_loftSurface',su=6,sv=1)
    mel.eval('DeleteHistory;')
    cmds.select('spineRibbon_loftSurface')

    #create hair splines
    mel.eval('createHair 7 1 10 0 0 1 0 5 0 1 2 1;')
    cmds.delete('hairSystem1')
    cmds.delete('pfxHair1')
    cmds.delete('nucleus1')
    cmds.rename('hairSystem1Follicles', 'spine_follicles_offset')

    #by putting a star at the end of the follicle in cmds.ls you've told maya to list everything starting with that name
    folName = 'spine_follicle'
    folList = cmds.ls('spineRibbon_loftSurfaceFollicle*')
    for name in folList:
        cmds.rename(name,folName)


    #delete proxy locators
    cmds.delete('spineLoc_1_PRX')
    cmds.delete('upLoftTemp')
    cmds.delete('dwnLoftTemp')

    #create waist curve

I want to know whats causing this error, and if possible I would also like to create a for loop to delete the groups named "curve" beneath the follicles.

Dasteel
  • 101
  • 18
  • I also forgot to mention, you use the script by by hitting "generate Spine Proxy Locators" after that you can use "spineLoc_2_PRX" to determine the length of the spine loft surface. The error occurs when you hit "Build Spine Joints" – Dasteel Feb 25 '20 at 06:49

1 Answers1

2

The error occurs in this portion:

for name in folList:
    cmds.rename(name, folName)

If you add a print statement to print name and run cmds.objExists on it, it'll give you:

True spineRibbon_loftSurfaceFollicle50
True spineRibbon_loftSurfaceFollicle1750
True spineRibbon_loftSurfaceFollicle3350
True spineRibbon_loftSurfaceFollicle5050
True spineRibbon_loftSurfaceFollicle6650
True spineRibbon_loftSurfaceFollicle8350
True spineRibbon_loftSurfaceFollicle9950
False spineRibbon_loftSurfaceFollicleShape50

Maya is unable to find that last object, and thus, throws that error. Notice that the last one is a shape? That's because when you're calling cmds.ls('spineRibbon_loftSurfaceFollicle*') it's returning you a list of the transforms AND shapes. So as you're iterating through your loop and renaming each follicle, Maya is also auto-renaming its shape. Then eventually your loop iterates to the first shape, which was already auto-renamed, and fails.

The fix is easy: just make sure you grab the follicle's transform, not its shapes! You can do this by replacing line 72 with this: folList = cmds.ls('spineRibbon_loftSurfaceFollicle*', transforms=True), then it will work as expected.

Green Cell
  • 4,677
  • 2
  • 18
  • 49
  • Thank you very much @Green Cell, it works perfectly! I have one more question though, is it possible to create a For Loop that looks inside of the spine_follicles_offset group and deletes the curve groups it generated? – Dasteel Feb 26 '20 at 03:55
  • Of course, you can use `cmds.listRelatives` to get the follicle's children. – Green Cell Feb 26 '20 at 03:58
  • Alright, here is what I got @Green Cell: grpList = cmds.listRelatives('spine_follicle*') for name in grpList: print(grpList) cmds.delete('curve*') The only problem is now I'm getting the same error (no object matches name) Only this time I can use the transform flag – Dasteel Feb 26 '20 at 06:37
  • 1. Start getting in the habit of using `print` to see what your commands are outputting. 2. The documentation is actually very good, so check it out to see what parameters you can use to filter out the results 3. You need to stop referencing names directly as it'll make things so much harder. Capture results in variables and use them instead. 4. This is getting way off original topic, so if you have another issue post another question with a minimal attempt. – Green Cell Feb 26 '20 at 07:03