Tagged: Maya

Opening a newer version Maya file in an older version of Maya

A common issue when using AW Maya is trying to open a file that was created in a newer version of Maya than your installed version. Maya files are not backwards compatible, in my experience. There are two ways that I know of to deal with this. One is to simply select “Ignore Version” in the File->Open dialog. I tried this today and it failed, Maya crashed. Another option, which did work for me, is to save the newer version file as an ASCII file (file.ma), and edit the file’s data manually. This is very simple to do. You will need to have access to the newer version of Maya to accomplish this though, or have your collaborator deliver an ASCII version of the file. Once you have the ASCII file, do the following things:

1) Save a dummy ASCII file from your older version of Maya (ex: dummyFile.ma) so that you can see the older format file’s data. For safety, make a copy of your “Newer Version” file, as you will be editing the code directly.

2) open both files side by side examine the “headers”, the top portion of each file. You will note a similarity in the first 10 – 15 lines of data. I am using a Mac, so examining the files, the last line I see in what I would call header information is: fileInfo "osv" "Mac OS X 10.8.2";. After this there is a “createNode” Maya command, that I don’t want to disturb. It’s slightly different from one file to another and one version to another, but only slightly. You will have no trouble figuring out where to copy and where to paste. Copy this header data from the older version file and paste to the newer version file, overwriting the relevant code.

2) The file should now open in the older version of Maya. Of course any features of the newer version of Maya that are not available in the older version of Maya will not work in this opened scene (actually I’m not certain what happens in this scenario).

There may be other methods, but I am not aware.

Maya particle instancing with real flow rain drops



Create animated instances geometry at a particle collision.

For my raindrop splash, I am using an animated sequence of geometry, created in realflow (70mb). The realflow bin sequence is a single node after it is imported to Maya, it needs to be converted (duplicated) to a sequence of Maya nodes, multiple nodes. Use the following MEL script to convert the bin to multiple nodes.

[c]//Select your realflow imported bin
string $bin[] = `ls-sl`;
//this is set up to to "convert" (duplicate) the bin from frame 1 – 100. Set the frame range that you want to convert below.
for( $index = 1; $index <= 100; $index++ )
{
currentTime $index;
select $bin[0];
duplicate;
select -cl ;
}[/c]

Now you should have a sequence of separate meshes, each representing a frame of your instanced animation. These will be loaded into the “particle instancer” to allow for animation at the point where each particle collides.

Create a collision event for your particle
1. Select particle and collision object and go to Menu : Particles > Make Collide
2. Set a particle collision event for your selected particle. Particles > Particle collision event editor. Set: event type to “emit”. Set: inherit to 0. Set: 1 particle emitted per collision. Set: Original Dies.
3.Press the create event button. A new particle object will be created.

Instance the geometry to the newly created particle.
1.Go to Menu>Particles > Instancer options
2. Load your sequence of separate meshes into the “Instanced Objects” section. Make sure that your particleShape is NOT loaded into the create instancer as an instanced object as it will try and instance itself.
3. Set: particle object to instance to : particleShape2 or whatever the particle object that was created by the collision event.
4. Select the newly created particle object shape. In the attribute editor, set: the lifespan of the particle to the duration of you splash object geometry sequence (number of individual nodes). The lifespan is in seconds…so you will need to do the math to get your frame count..

Python import/export Maya keyframes script

These are fairly rudimentary python scripts, to export keys from Maya and import them back into Maya. Creates a key at every frame. May be interesting to people learning Python.

Export Maya Keys
[py]
import maya.cmds as mc
# Select all nodes with keys to export
# Customize the path below so that it points to, or creates, the file where you want to store the keyframe data
myFileObject=open(‘/mydataDir/data.txt’, ‘w’)
obs = mc.ls(sl=True)
theData = []
minTime = mc.playbackOptions(query=True, minTime=True)
maxTime = mc.playbackOptions(query=True, maxTime=True)
attributes = [‘translateX’, ‘translateY’, ‘translateZ’, ‘rotateX’, ‘rotateY’, ‘rotateZ’, ‘scaleX’, ‘scaleY’, ‘scaleZ’, ‘visibility’]
for time in range(minTime -1, maxTime +1):
mc.currentTime(time)
count = 0
for selection in obs:
name = obs[count]
count +=1
for theAttribute in attributes:
myAtF = mc.getAttr(selection + ‘.’ + theAttribute)
myAt = str(myAtF)
myTime = str(time)
theData.append(myAt + ‘ ‘ + myTime + ‘ ‘ + theAttribute + ‘ ‘ + name + ‘ \n’)
for lines in theData:
myFileObject.writelines(lines)
myFileObject.close()
[/py]

Import Maya Keys
This will import keys to nodes which are named identically to the nodes that were selected when the keys were exported.
[py]
import maya.cmds as mc
# Customize the path below so that it points to the file where you have exported the keyframe data
myFileObject=open(‘/mydataDir/data.txt’, ‘r’)
theLines = myFileObject.readlines()
count = 0
for line in theLines:
theLine = theLines[count]
theSplit = str.split(theLine)
theValue = theSplit[0]
theFrame = theSplit[1]
theAttribute = theSplit[2]
theName = theSplit[3]
mc.setKeyframe( theName, v=float(theValue), at=theAttribute, t =float(theFrame))
count +=1
myFileObject.close()
[/py]

Animating with audio

Importing keyframe data to Maya

Use this python script to import keys to a single channel of each node in a group of selected objects. This setup, below, will import properly formatted keys to the .translateY attribute of selected objects.

This script will apply unique keys to each selected node if there is a corresponding number of data files in the source directory.

[py]import os
import maya.cmds as mc
## add path to keyframe data files – just the source directory that contains them.
rootdir=’/path/to/keys’
## "ty", in line 13, refers to the Maya attribute channel of the selected objects. Modify this attribute as necessary.
objs= mc.ls(sl=True)
for subdir, dirs, files in os.walk(rootdir):
for thisFile, o in zip(files, objs):
file = open((os.path.join(rootdir, thisFile)), ‘r’)
lines = file.readlines()
file.close()
for i in range(len(lines)):
mc.setKeyframe(o, at=’ty’, v=float(lines[i]), t=i, itt=’linear’, ott=’linear’)
[/py]

See a sample of properly formatted keyframe data :
http://oliverwolfson.com/scripts/keyFrameData.txt

Also see http://oliverwolfson.com/extracting-raw-key-frame-data/

NEW! The script below will do the same as the script above, import After Effects Sound Keys keyframes, from .txt files, to Maya, but it will also take care of the formatting, so there is no need to run a shell script on your After Effects keyframes before importing.

This script will apply unique keys to each selected node if there is a corresponding number of data files in the source directory.

[py]##AE Import
import os
import maya.cmds as mc
## add path to keyframe data files – just the source directory that contains them.
rootdir=’/Volumes/500GB/Work/Code/python/AEkeysImport/soundkeys’
## below is the attribute that you want to keyframe
theAttribute = ‘translateY’
count = 0
objs= mc.ls(sl=True)
for subdir, dirs, files in os.walk(rootdir):
dataFiles = [each for each in files if each.endswith(‘.txt’)]
for thisFile, o in zip(dataFiles, objs):
theName = objs[count]
count +=1
dataFile = open((os.path.join(rootdir, thisFile)), ‘r’)
lines = dataFile.readlines()
dataFile.close()
mylines = lines[10:-4]
for eachLine in mylines:
data = eachLine.split(‘\t’)
theFrame = data[1]
theValue = data[2]
mc.setKeyframe( o, v=float(theValue), at=theAttribute, t =float(theFrame))
[/py]

Note: When pasting the keys from After Effects, be sure to use a code text editor like BB Edit or Text Wrangler. These apps will save your .txt files with UNIX line returns which is necessary to make this script work properly.

Technically the line breaks are invisible, but using the ‘tr’ command, in a UNIX shell, you could display them as any character you like, eg:

[shell]
cat /path/some/file.txt | tr ‘\n’ ‘U’
[/shell]

In the above example, if the input file uses UNIX style line returns, \n ,each line will have a U at the end.

Maya Render Settings, File Name Prefix

Adding a path to the File Name Prefix dialog in the Render Settings will force Maya to write the sub directories specified:

You can write, for instance: subdir/renderPass1/myRen.

This will write files called myRen.####.ext into the directory path images/subdir/renderPass1/, as long as you are set up to render into the images directory.

You can use % to indicate variable values:

%s: scene name
%c: camera
%l: render layer

Example: %s/%c/%l/%s_%l

Creating a Maya batch render script

Creating a Maya batch render script for a PC using Windows has always been straightforward in my experience. You simply write a text file with the following code:

render /path/to/myFile.mb

Make the file executable by changing the extension to .bat. Double click the file to launch the render.

The renderer will use settings that were selected when the project was saved. Those settings can be over-ridden with render flags. See Render Flags below for render flags and options.

For the Mac, it can be slightly less straightforward. Follow these instructions, found on Autodesk, The Area

Issue

You are on Mac OS X and you want to render several files one after another using a batch script.

Solution

To batch render multiple scene files, you need to create a shell script, for example: myRender.sh.

1. Using a text editor (Applications > Textedit), enter the render command for each individual scene on a separate line.

#!/bin/bash
Render –r sw scene1.mb
Render –r sw scene2.mb
Render –r sw scene3.mb

In some cases, you may need to enter the complete path of the Render command. It is located here:

/Applications/Autodesk/maya2009/Maya.app/Contents/bin/Render
(of course, different for later versions of the software)

2. Save the file on your desktop as: myRender.sh.

3. You will need to change the file permissions of myRender.sh to 755.

Open the Maya Terminal (Applications > Autodesk > Maya2009 > Maya Terminal) and type:

chmod 755 /Users/YOUR-USERNAME/Desktop/myRender.sh

4. Now run the script from the Maya terminal by typing:

/Users/YOUR-USERNAME/Desktop/myRender.sh

(note! A shortcut to typing file paths in the terminal: Just drag the file to the terminal window!)

Code:

 
#!/bin/bash /Applications/Autodesk/maya2009/Maya.app/Contents/bin/Render -rd /path/to/render/output/folder /path/to/myFile.mb

Render Flags

Render flags are “options” code. For example in Render -rd, -rd is the flag, which allows you to set the exact render directory, i.e. where your rendered images will be saved.

 
Render -rd /path/to/render/output/folder

Do a search in the help for more render flags (options):
render -h in the terminal.

 
/Applications/Autodesk/maya2009/Maya.app/Contents/bin/Render -h

Popular Render Flags:

-proj
#Use this flag to ensure you are rendering to the proper project: -proj /path/to/projectDirectory

-s, -e
#specify start and end frames: -s 0 -e 100

-r
# Specify renderer: -r mr for mental ray (or : sw, hw, etc)

-rt
# Render threads, specify number of cpu threads, I use -rt 8 for my Mac Pro Quad (Mental Ray only)

-rl
# Specify render layer by name: -rl layer1

-cam
#Specify camera to render by name

-rd
# specify render image path: -rd /path/ to/image/folder/

-im
# specify image name: -im myImageName

If you are using Render layers use the following flags and setup:

-rl boolean|name(s)

Set up like this:

Render -rl layer1 /path/to/file1.mb
Render -rl layer2 /path/to/file1.mb

More info on render flags:

Maya render flags: http://www.pdipierro.com/tutorials/MayaRenderFlags.html

Also see
http://oliverwolfson.com/maya-render-settings-file-name-prefix/

MEL change attribute on multiple objects

Using the channel box or the attribute spreadsheet are good ways to manually change attributes on multiple selected objects.

In MEL, this script is set up to change attributes on selected nodes in the scene.

string $mySel[] = `ls-sl`; string $name; int $arraySize = `size $mySel`; for ($i = 0; $i < $arraySize; $i++) { $name = $mySel[$i]; $myNode = ($name + ".rotateX"); setAttr $myNode 100; }

If you want to make changes to the shape node, you will want to use ls -sl -dag -leaf:

string $mySel[] = `ls -sl -dag -leaf`; for ($each in $mySel) { setAttr ($each +".attribute") 1; } print $mySel;

Duplicate, and Constrain MEL script

Here is a script that duplicates an object and then constrains it to another animated object. In this case a stack of low res, dynamically animated coins are replaced by textured coin model.

string $mySel[] = `ls -sl`; int $arraySize = `size $mySel`; print $arraySize; int $i = 0; for ($i = 0; $i < $arraySize; $i++) { string $dupPenny[] = `duplicate penny1`; select $dupPenny; group -name ("pennyGRP" + $i); CenterPivot; select $mySel2[$i]; select -tgl ("pennyGRP" + $i); pointConstraint -offset 0 0 0 -weight 1; orientConstraint -offset 0 0 0 -weight 1; }

This script also groups the new coin, so it can be offset.

Maya stereo camera rig

Maya 2009 automates stereo anaglyph rendering. Put on some red and cyan filtered 3D glasses to see the depth effect.

This image is rendered through a stereo camera (Create->Cameras->Stereo Camera), using anaglyph mode. I altered the settings for the interaxial separation (0.1), Zero Parallax, and the Toe In Adjust (0).

To render both left and right cameras, I enabled “renderable”, in the output settings, on the left and right camera nodes of the stereo camera rig.

To composite this render, a stereo pair of left and right camera image sequences, I used the “Set Channels” effect in After Effects. On the left camera renders, I removed green and blue, leaving a red image, on the right I removed the red, leaving cyan. The blend mode is “Add”. The result will give a 3D depth effect if viewed through red/cyan filtered 3D glasses.

—-

3DGlasses

For this image, I altered the settings for the interaxial separation (0.365) and the toe in adjust (.25).

Download the scene.

This link may be useful!

Also see: http://oliverwolfson.com/3d-dynamics/