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.
Typos everywhere.
Upon initial run of the code I get this:
To fix I change line 26 from
create_random_sphere()tosphere = create_random_sphere().Running again I get your current issue:
In line 32, change
create_pipe(sphere[i],spheres[i+1])tocreate_pipe(spheres[i],spheres[i+1])to fix.That then results in
Fixed by changing line 18 from
cmds.curve(...tocurve = cmds.curve(....That then results in:
Because on line 32 you did
create_pipe(spheres[i],spheres[i+1])instead ofpipe = create_pipe(spheres[i],spheres[i+1])Running it after that results in this: