Jump to content

Python in Maya - problem with a basic loop

Go to solution Solved by Enderman,

you need to do == not =

 

= is stating x = y

== is checking if x == y

So I've got an assignment that requires a loop and an if/else statement in Maya 2014. Straightforward enough, however I am restricted to python, no Pymel. Currently I have this:
 

import maya.cmds as cmdsdef mySpike(x,y,z):    for i in range(0, 50):        if i%2 = 0:            cmds.polySphere(r=2)            cmds.move(i+5,i+10,i)            cmds.xform(ws=True, rotatePivot=(0,0,0))            cmds.rotate(x*i,y*i,z*i)            cmds.hyperShade(a='EMP')              else:            cmds.polySphere(r=2)            cmds.move(i+5,i+10,i)            cmds.xform(ws=True, rotatePivot=(0,0,0))            cmds.rotate(x*i,y*i,z*i)            cmds.hyperShade(a='FRAG')mySpike(0,15,0)

The issue I'm having is that it's giving me a "syntax error @ line 1" and is referring to my use of 

if i%2 = 0:

The idea was to create a sphere, move it, set its rotational pivot to the origin, rotate around that new pivot and then apply a material based on the return of i%2 (both if/else outputs are the same, except for the material chosen).

Can someone help me understand why I can't go straight from a looping range into an if evaluation?

Link to comment
https://linustechtips.com/topic/219981-python-in-maya-problem-with-a-basic-loop/
Share on other sites

Link to post
Share on other sites

you need to do == not =

 

= is stating x = y

== is checking if x == y

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to post
Share on other sites

Oh my goodness, i'm making a comparison not setting a value, thank you so much! No idea how I overlooked that *blush* embarrassing thread >.<

You're welcome :)

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to post
Share on other sites

Oh my goodness, i'm making a comparison not setting a value, thank you so much! No idea how I overlooked that *blush* embarrassing thread >.<

No worries. I had a function a couple of days ago which I forgot a return in and did not figure out what was wrong with it since the lambda variant worked in the console. Posted it in a skype chat with some buddies asking them for help and instantly noticed my error. Ooops.
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×