vi text editor introduction

vi, text editing program for the Unix/Mac terminal.

To open vi, open a file, or create a file type: vi file_name in a terminal window. Or more specifically vi path/to/filename.ext. For example: vi ~/Desktop/hello.sh will open, or create, a file on the Desktop called hello.sh.

To start adding text you need to be in insert mode! hit the i key to get into insert mode.

To delete text, in insert mode, press x for single characters. Press dw for entire words. Press dd to delete entire lines.

To save a file, first hit the ESC key, to enter “command mode”, then type: :w, then hit ENTER (colon+w ENTER)

To exit vi , first hit the ESC key, then type : :q, then hit ENTER (colon+q ENTER)

You can save AND exit by typing :wq, while in command mode.

To move to the beginning of a line, in command mode hit 0 (zero), the end hit $.

Vi cheat sheet

more info here
and here

Shell Scripting Notes – Apple Primer

Shell scripting primer from Apple:

http://developer.apple.com/mac/library/documentation/opensource/conceptual/shellscripting/Introduction/Introduction.html

poem.txt
foo.txt

Samples:

You can use regular expressions to search for strings in a file or a block of text by using the grep command. For example, to look for the word “bar” in the file foo.txt, you might do this:

grep "bar" foo.txt # or cat foo.txt | grep "bar"

Positional anchors allow you to specify the position within a line of text where an expression is allowed to match. There are two positional anchors that are regularly used: caret (^) and dollar ($). When placed at the beginning or end of an expression, these match the beginning and end of a line of text, respectively.

For example:

# Expression: /^Mary/ grep "^Mary" < poem.txt

This matches the word “Mary”, but only when it appears at the beginning of a line.

Animating with audio

This animation was created using After Effects and Maya.

Getting audio key frames out of After Effects using Trapcode Sound Keys.

Extracting raw key frame data from After Effects formatted keyfame data that can be used by Maya, via shell script.

Importing keyframe data to Maya using Python.

Creating Maya shaders that react to audio key frames

Outputting a depth map from Maya and creating depth of field in After Effects.

Maya duplicate and move by frame

Duplicate and move based on the frame number. This MEL script will duplicate your object once per frame (set up to be 0 – 30 in this script) and move it to a position based on the frame number (this script: 0 – 30, 0, 0).

Usage: select your object and run script.

string $myObj[] = `ls -sl`; for( $index = 0; $index <= 30; $index++ ) { currentTime $index; select $myObj[0]; duplicate; move -a $index 0 0 ; }

Possible uses: This can help if you have an animated object and you want to save the position at each frame as a separate piece of geometry.

Shattering Glass Dynamic Simulation

Maya rigid bodies and Mental Ray.

using Maya setRange to control incandescence

setRange is a utility node that allows you to take values in one range, and map them into another range. Here is an example of setRange being used to remap the value of the translateY attribute to new values that control the incandescence of a shader.

This MEL script will create and attach a shader to selected objects, which links the translateY value of a Maya object to the incandescence of the shader.

The setRange utility is placed in between to control the output value range going into the shader. In this case, if the object’s translateY value is 10 the output will be 2, 1.25, 2, which produces a bright magenta color, if used as RGB values.

Using Maya hsvToRgb to cycle through the color spectrum

HSV to RGB is a utility node that allows you to convert an HSV (Hue-Saturation-Value) color into an RGB (Red-Green-Blue) color.

.inHsvR ranges from 0 to 360, representing degrees of a circle. We can use this to animate a shader to run through all the rainbow colors.

This MEL script will create and assign this shader network to selected objects.

coffee

morning ritual from oliver wolfson on Vimeo.

Shell scripting notes

A shell script is a script written for the shell, or command line interface: Terminal. Typical operations performed by shell scripts include file manipulation, program execution, and printing text.

Examples of uses for shell scripts:

  • Editing large text or data files.
  • Automating tasks, such as backup operations.



You can write a shell script to a text file to perform various tasks on your Mac.

Example:

#!/bin/sh if [ -f ~/Desktop/hello.sh ]; then say Hello! fi

Save this code to a text file named hello.sh, on your desktop. It is best to use a program like Text Wrangler, or vi. Open the Terminal (in the Applications/Utilities/ folder) and type: chmod +x ~/Desktop/hello.sh, to make the file executable. To run the script type: ~/Desktop/hello.sh in a terminal window.

#!/bin/sh tells the shell to run the program in sh, a type of shell program.
if and fi are the beginning and end of an “if statement”. Allows execution of certain commands if certain arguments are true.
[ -f ~/Desktop/hello.sh ] is the argument. It means: if the file hello.sh exists on the desktop, do the commands that follow the “then” statement.
say Hello! is the command. This should cause your Mac to say “Hello!”.

You will need learn some basic Unix commands to get around in the command line interface. Read a Mac Terminal tutorial (pdf). The basics can be learned quickly. Below are a few commands that you need to know:

ls
, list the contents of the current directory.
pwd, print the path to the current directory to screen.
cd, change directory. Ex: cd ~/ will change directories to your user home directory.
chmod, changes permissions. Vital, but best to do a tutorial on this one.
mkdir, create a new directory.

Using the Terminal in OSX and Linux is similar.

Utilities/commands useful for shell scripting.

awk A programming language that is designed for processing text-based data. awk video
grep Text search utility originally written for Unix. grep video grep video 2
cat Unix program used to concatenate and display files. cat video
sed is a Unix utility that (a) parses text files and (b) implements a programming language which can apply textual transformations to such files. Sed video

Example grep: this lists (ls) the items in the current directory, and recognizes directories in the list by using the -F option ( you will note the / after list items that are directories). The pipe (|) forwards the result to grep, which filters for directories because we used “/” as the argument.

ls -F | grep /

Example grep and awk: df lists the drives and partitions and disk space on the computer. -h makes it more (h)uman readable. Pipe (|) into grep is filtered for one of the disks, named disk0s2. Pipe (|) awk prints only the 5th column ($5). The result is just the disk space used ex: 39%.

df -h | grep disk0s2 | awk '{print $5}'

or just use awk in this format to get the same result

# more efficient df -h | awk '/disk0s2/ {print $5}' # prints it out in human readable formatting. df -h | awk '/disk0s2/ {print $1 " is " $5 " used. "}'

More info from shell scripting primer from Apple:

http://developer.apple.com/mac/library/documentation/opensource/conceptual/shellscripting/Introduction/Introduction.html

Advanced Bash-Scripting Guide

An example of a shell script in action, and a detailed explanation of its functionality.

Outputting a depth map from Maya and creating depth of field in After Effects

Create a render layer that contais the objects that will be blurred. Use “Luminance Depth” preset.

The depth map render will look something like this. A gradient, which describes depth. Objects further from the camera are shaded increasingly darker.

Bring your color render and the depth map into a composition in After Effects. You can switch off the visibility of the depth map layer. It will only be used by the Lens Blur Effect to guide hich areas will receive blur.

Apply the Lens Blur effect to the color render layer. Select the depth map layer as the “Depth Map Layer”.

Adjust attributes to get the result needed. Here only the “Blur Focal Distance” (focus region distance from camera) and the ” Iris Radius”(blur amount) were adjusted.