View Full Version : creating a clock animation using python/expressions
gunner89 01042011, 09:56 AM hi, i have to create a clock that is animated and runs correctly for an hour (hour, minute and second hands) heres what i have so far to create the markers but im getting errors. I would greatly appreciate any help.
import maya.cmds as cmds
import math
radius=10
for i in range(0,360,6):
if i %30 == 0:
cmds.polyCube()
else
cmds.move(rad*math.cos(30*2*math.pi/360),rad*math.sin(30*2*math.pi/360)y=True)


NaughtyNathan
01042011, 03:13 PM
why not just try this:
mayaClockDemo; // MEL;)
:nathaN
pixelranger
01042011, 10:58 PM
whaaaaaaaaaaaaaat?!? Heh thats probably the coolest thing I've learnt this whole year!!
gunner89
01062011, 03:47 PM
Well I need to create the animation using python and maya expressions. The clock model has to be created by the code and not pre modeled. Ive got code to create the clock hands ect:
## Creating Minute Hand ##
import maya.cmds as cmds
minHand=cmds.polyCube(w=0.75, h=10, d=0.25, n="minHand")
cmds.move(0,5,0)
cmds.move(0,0,0, minHand[0] + ".rotatePivot")
But when it comes to creating the hour markers, this for loop doesnt work and says 'invalid syntax':
## Creating Hour Markers ##
import maya.cmds as cmds
import math
rad=10
for i in range(0,360,6):
if i %30 == 0:
cmds.polyCube()
else
cmds.move(rad*math.cos(30*2*math.pi/360),rad*math.sin(30*2*math.pi/360)y=True)
I've got a feeling its something to do with the math functions but cant figure out what.
Any help would be greatly appriecated
WesHowe
01062011, 08:11 PM
cmds.move(rad*math.cos(30*2*math.pi/360),rad*math.sin(30*2*math.pi/360)y=True)
Shouldn't there be a comma right before "y=True"?
gunner89
01072011, 11:48 AM
cmds.move(rad*math.cos(30*2*math.pi/360),rad*math.sin(30*2*math.pi/360)y=True)
Shouldn't there be a comma right before "y=True"?
Nope that still doesn't work, still getting an 'invalid syntax' error :s
NaughtyNathan
01072011, 12:21 PM
you are missing a : after your last else.
:nathaN
Matt1882
01092011, 01:24 AM
Hi, I'm trying to do the same sort of thing, but when I run the for range i dont get the correct results. I want the hour markers to be correctly aligned (as they would be on a clock) but for some reason there not being created at the right points (picture attached).
## Creating Hour Markers ## import maya.cmds as cmds
import math
rad=10
for i in range(0,360,6):
if i %30 == 0:
cmds.polyCube()
else:
cmds.move(rad*math.cos(30*2*math.pi/360),rad*math.sin(30*2*math.pi/360),y=True)
cmds.move(rad*math.cos(i),rad*math.sin(i),0)
Im probably doing doing something simple wrong, but I cant for the life of me figure out what!
Any help would be awesome
Thanks
NaughtyNathan
01092011, 10:53 AM
I'm not sure what you were both thinking, but this makes more sense:
## Creating Hour Markers ##
import maya.cmds as cmds
import math
rad=10
for i in range(120,480,30):
cmds.polyCube()
cmds.move(rad*math.cos(i*2*math.pi/360),rad*math.sin(i*2*math.pi/360),0)
This way, the first cube is actually at the "1" position, your loop is only the 12 steps it should be, and there are no pointless if conditions. (it could still be imporved further, but I've tried to leave it as close to the original as possible).
:nathaN
CGTalk Moderation
01092011, 10:53 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©20002015, Jelsoft Enterprises Ltd.