Why does maya show a value error when there is no object?

55 Views Asked by At

I'm following along with a lecture for class, its Python in maya and I've run into the issue that on line 18 "no object matches name:p", I'm not sure what this means, the p its referecing comes from the word point, which is supposed to draw on information from the spheres location.

import maya.cmds as cmds
import random

def create_random_sphere():

    x = random.uniform (-100,100)
    y = random.uniform (-100,100)
    z = random.uniform (-100,100)
    
    sphere = cmds.polySphere()[0]
    
    cmds.move(x,y,z, sphere)
    
    return sphere
    
def create_pipe(start,end):

    cmds.curve(degree = 1, point=[cmds.xform(start,query=True,translation=True), cmds.xform(end,query=True,translation=True)])

    return curve

def create_spheres_pipes(num_spheres):
    spheres = []
    
    for i in range(num_spheres):
        create_random_sphere()
        spheres.append(sphere)
        
    pipes = []
    
    for i in range(len(spheres)-1):
        create_pipe(sphere[i],spheres[i+1])
        pipes.append(pipe)
        
    pipe= create_pipe(spheres[-1],spheres[0])
    pipes.append(pipe)
    return spheres, pipes

def createspheresandpipes(num_spheres):
    spheres, pipes = create_spheres_pipes(num_spheres)
    
    circle = cmds.circle(normal=(0,1,0),radius= 0.2)
    
    for pipe in pipes:
        cmds.select(circle[0],pipe)
        cmds.extrude(et=2,ucp=1,fpt= True,upn=True)
createspheresandpipes(10)

The goal is to make a bunch of randomly generated spheres with pipes connecting them, I can not get the pipes to generate.

1

There are 1 best solutions below

0
Peter On

Typos everywhere.

Upon initial run of the code I get this:

# Traceback (most recent call last):
#   File "<maya console>", line 47, in <module>
#   File "<maya console>", line 40, in createspheresandpipes
#   File "<maya console>", line 27, in create_spheres_pipes
# NameError: global name 'sphere' is not defined #

To fix I change line 26 from create_random_sphere() to sphere = create_random_sphere().

Running again I get your current issue:

# Traceback (most recent call last):
#   File "<maya console>", line 47, in <module>
#   File "<maya console>", line 40, in createspheresandpipes
#   File "<maya console>", line 32, in create_spheres_pipes
#   File "<maya console>", line 18, in create_pipe
# ValueError: No object matches name: p # 

In line 32, change create_pipe(sphere[i],spheres[i+1]) to create_pipe(spheres[i],spheres[i+1]) to fix.

That then results in

# Traceback (most recent call last):
#   File "<maya console>", line 47, in <module>
#   File "<maya console>", line 40, in createspheresandpipes
#   File "<maya console>", line 32, in create_spheres_pipes
#   File "<maya console>", line 20, in create_pipe
# NameError: global name 'curve' is not defined # 

Fixed by changing line 18 from cmds.curve(... to curve = cmds.curve(....

That then results in:

# Error: local variable 'pipe' referenced before assignment
# Traceback (most recent call last):
#   File "<maya console>", line 47, in <module>
#   File "<maya console>", line 40, in createspheresandpipes
#   File "<maya console>", line 33, in create_spheres_pipes
# UnboundLocalError: local variable 'pipe' referenced before assignment #

Because on line 32 you did create_pipe(spheres[i],spheres[i+1]) instead of pipe = create_pipe(spheres[i],spheres[i+1])

Running it after that results in this:

enter image description here