View Single Post
# 11 02-05-2013 , 03:29 AM
NextDesign's Avatar
Technical Director
Join Date: Feb 2004
Posts: 2,988
Sure, it's possible. I would recommend changing the format of the text file to make it easier to work with.

For example, having the frame number is fine, but not useful for the script. You could just use the column number in Excel as this instead. However the kicks pose a bit of a problem. Since the easiest way to write this out would be as a CSV file, you might get an empty column at the end, or in the middle, which complicates the code by trying to fix this. Instead, you can encode both kicks into a single number. For example:

Nothing = 0
Kick 1 = 1
Kick 2 = 2
Kick 1 & 2 = 3

Then you can do the following:

1) Save your table out as a CSV file
2) Go to the first frame (https://download.autodesk.com/us/maya...rrentTime.html)
2) Go through the file line by line (See this for help: https://www.scriptswell.net/2010/09/m...text-file.html)
3) For each line, tokenize it, using a comma as a delimiter. (https://download.autodesk.com/us/maya.../tokenize.html)
4) Go to time i, where i is line number
5) Convert the second value of the array (kick number) into an integer.
6) If the value equals 0, don't do anything. If it equals 1, set the locator to a certain position. If it equals 2, set it to another position. If it equals 3, set it to yet another position.
7) Key this position (https://download.autodesk.com/us/maya...tKeyframe.html)
8) Continue to loop until done.

So you'll have something like this (This is pseudo-code, and will not run!):
Code:
file = read filename

data = read file

go to time 1

for i = 0 to number of lines in data
{
    go to time i

    line = ith line of data

    tokens = tokenize line by comma

    kickVal = (int)tokens[1]

    if (kickVal == 1)
    {
        set locator to position 1
        set keyframe on locator
    }
    else if (kickVal == 2)
    {
        set locator to position 2
        set keyframe on locator
    }
    else if (kickVal == 3)
    {
        set locator to position 3
        set keyframe on locator
    }
}
Hopefully this helps you out.


Imagination is more important than knowledge.