Issue on how to give range for currentTime

Issue on how to give range for currentTime

Anonymous
Not applicable
826 Views
3 Replies
Message 1 of 4

Issue on how to give range for currentTime

Anonymous
Not applicable

Hello everyone,
I am a newbie in Maya python, I am stuck in a script please help. so here is the base that I want to create with the script.

I have a trail of cubes in Maya scene I want my sphere to follow that cube trail by getting the values of the cube translation. I have been trying it, however, I am not getting what I want. Please help. Below is the image please look at it.

0 Likes
827 Views
3 Replies
Replies (3)
Message 2 of 4

stuzzz
Collaborator
Collaborator

I'm not sure to understand what you're trying to do but try this one:

 

import maya.cmds as cmds
#not a fan of mc, sorry

#do your selection as usual, the order is important
sphere = cmds.ls(sl=True)[0]
cubes = cmds.ls(sl=True)[1:]

#set your time frame
timeRange =[0.0,50.0]

#enumate would help for your purpose
for e,cube in enumerate(cubes):
    #query the position of the current cube
	pos = cmds.getAttr('%s.tx' % cube)
    #we are basically getting the ratio
	delta =  (timeRange[1] - timeRange[0]) / len(cubes)
    #offset that ratio with the start time and multiply with the index
	finalTime = timeRange[0] + (delta * (1+e)) 

	cmds.setKeyframe(sphere, t=finalTime ,v=pos, at='translateX')
0 Likes
Message 3 of 4

Anonymous
Not applicable

thanx, buddy it worked. kudos to you.

Message 4 of 4

stuzzz
Collaborator
Collaborator

Awesome, glad to help.

If you can accept my answer as a solution.

 

Thanks!

0 Likes