Category: how to

determining the bounding box of a Maya object

float $boboArray[] = `polyEvaluate -b pCube1`;

for a default cube, this will return : // Result: -0.5 0.5 -0.5 0.5 -0.5 0.5 //, the units returned correspond to the 6 coordinate locations of the cubes vertices.

float $boboArray[] = `polyEvaluate -b pSphere1`;

for a default sphere, this will return : // Result: -1 1 -1 1 -1 1 // , the units returned correspond to the coordinate locations of the a cube that is “fitted” to the sphere’s bounding box.

Add a processing applet to a blog post

Anyone know how to do this? HELP! 😀 I am trying to figure it out.

I want to do it specifically for WordPress, but any info would be welcome.

Here is the applet working at another url.



<APPLET name="sketch_oct28a" WIDTH="600" HEIGHT="400" archive="" standby="Loading Processing software…" codebase="" code="" mayscript="true" scriptable="true" image="" boxmessage="Loading Processing software…" boxcolor="#FFFFFF">
<IMG SRC="" WIDTH="1" HEIGHT="1" />

Arduino Time Lapse Remote for Nikon

Nikon Remote, controlled by an Arduino Duemilanove, set up for time lapse photography.

Nikon D70
Nikon Remote Controller ML-L3
Arduino Duemilanove

Here is the code, which triggers the shutter every 6 seconds. Based on the “Blink” code that is included in the Arduino IDE, with the only modification being the blink time.

Time Lapse, based on Blink.
Triggers camera’s shutter every six seconds.

This example code is in the public domain.

void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);

void loop() {
digitalWrite(13, HIGH); // 0n, trigger the Shutter
delay(3000); // remain on for three seconds
digitalWrite(13, LOW); // Off
delay(3000); // wait for three seconds

Nikon Remote Controller ML-L3

Nikon Remote Controller ML-L3 circuit board, with the case removed. I soldered wires to the positive and negative battery terminals, marked in red.

Nikon Remote Controller ML-L3 circuit board, back side. The central zig zagging printed circuit is the circuit that will trigger the infrared LED. I closed the circuit by taping a wire across it, as illustrated by the red line.

The positive wire, from the remote is inserted into pin 13 of the Arduino (I used black for positive, though red would have been a more logical choice ;)). The negative wire is inserted into the GND pin. As the Arduino “Blinks” it supplies power to the remote, and triggers the shutter.

Power is supplied to the Arduino from a 9 volt battery.

Nikon D70’s infrared receiver.

Test: The remote device narcissistically photographs itself.

See for the tutorial that inspired this experiment.

create a grid of cubes

Grid of cubes in Maya.

# create a grid of cubes, their bottom plane set to zero y, and the center point at zero y.
x = -20
count = 0
cubes = []
while x <= 20:
z = -20
while z <= 20:
cube = mc.polyCube( name = (‘polyCube_’ + str(count) + ‘_’ + str(x) + str(z)) )
count +=1
mc.setAttr((cubeName + ‘.translateY’), .5);
mc.makeIdentity(apply=True, t =True, r=True, s=True, n= 0)
mc.move(x, 0, z)
z += 1
x +=1

Block of cubes

import maya.cmds as mc
# create a block grid of cubes
# change the mult number below to change the amount of cubes created.
mult = 3;
count = 0
cubes = []
y = mult – mult
while y <= mult *2:
x = mult * -1
while x <= mult:
z = mult * -1
while z <= mult:
cube = mc.polyCube( name = (‘cube_’ + str(count) ) )
count +=1
mc.move(x, y, z)
z += 1
x +=1
y +=1

Make a 3d cube grid, based on a selected object’s bounding box.
proc makeCubeGrid(int $cubeGridDiv)
string $cube[];
string $cubes[] = {};
string $sel[] = `ls -long -sl`;
float $bBox[] = `polyEvaluate -b -ae $sel[0]`;

float $w = ($bBox[1] – $bBox[0]) / $cubeGridDiv;
float $h = ($bBox[3] – $bBox[2]) / $cubeGridDiv;
float $d = ($bBox[5] – $bBox[4]) / $cubeGridDiv;

float $p[3];
$p[0] = $bBox[0] + (($bBox[1] – $bBox[0]) / $cubeGridDiv) * $i;
$p[1] = $bBox[2] + (($bBox[3] – $bBox[2]) / $cubeGridDiv) * $k;
$p[2] = $bBox[4] + (($bBox[5] – $bBox[4]) / $cubeGridDiv) * $n;
$cube = `polyCube -w $w -h $h -d $d -sx 1 -sy 1 -sz 1 -ax 0 0 0 -ch 0`;
move ($p[0] + $w / 2) ($p[1] + $h / 2) ($p[2] + $d / 2) $cube[0];
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $cube[0];
$cubes[`size $cubes`] = $cube[0];
string $group = `group -em -n "cubes"`;
parent $cubes $group;


Newline / convert newline shell script

When pasting data to a text file, for use with python and other data editing tools, it may be better to use a code text editor, like BB Edit or Text Wrangler. These apps can save your .txt files with UNIX line returns which is necessary to make some scripts 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:

In the terminal type:
cat /path/some/file.txt | tr ‘\n’ ‘U’

In the above example, if the input file uses UNIX style line returns, \n ,each line will have a ‘U’ at the end, or nothing if the file is using another type of return.

To change line returns from Mac to Unix in a data file, try the shell script below.



newFile=`basename -s ".txt" $theFile`.UnixLineReturns.txt

theDir=`dirname $theFile`

echo "theFile: $theFile"
echo "newFile: $newFile"
echo "theDir: $theDir"

cat "$theFile" | tr ‘\r’ ‘\n’ > "$theDir/$newFile"

Apple Mac Pro Bluetooth issue solved

If you are using a Mac Pro with wireless Bluetooth devices, particularly a mouse, you may have noticed an annoying lag or stutter in the performance. I bought the Magic Mouse and a wireless keyboard to solve some ergonomic issues. Unfortunately, poor performance made the situation even worse. Now, after having fixed this problem, my wireless devices are working perfectly.

The problem seems to be poor reception from the Bluetooth unit that shipped with my Mac Pro. I solved this by installing a third party Bluetooth usb adapter. In order for the new usb Bluetooth to operate properly, I had to disable the original internal Bluetooth unit. The instructions to disable the Mac Pro’s Bluetooth are below:

Review the procedure for working on your Mac by downloading a manual here.

1. Turn off Mac Pro. Remove power cord. Remove case cover.
2. Remove the processor tray.


Mac Pro Processor Tray

3. Find the Bluetooth unit on the motherboard. It is located near the bottom, on the right hand side as you are looking into the case.


Mac Pro bluetooth unit

4. Remove the connector that connects the Bluetooth to the motherboard.


Mac Pro bluetooth connector

5. Replace processor tray, and close case.


bluetooth USB dongle

6. Install a usb Bluetooth adapter.

Above is the tiny IOGear USB 2.1 Bluetooth Micro Adapter GBU421, which seems to work well with my Mac.

Note: I am using an Intel based MacPro4,1, bought in 2009. If you are using an older Mac Pro, you may want to look at this article and this article, as I believe that the configuration is different.

Caveat: While I am fairly certain that the Mac Pro’s internal Bluetooth could use and antenna redesign, given that so many people are having this same issue, I was not able to completely resolve my issue until I moved the usb Bluetooth adapter up onto my Cinema display, which features usb ports, and is a bit closer to the wireless devices. When I placed the adapter on one of the Mac Pro’s USB ports, on the front of the tower, again the result was poor performance. This leads me to believe that there is some interference from my furniture as well.

Note: If you are using a Magic Mouse, Magic Prefs is a must. It greatly expands the functionality of the Magic Mouse.


Rsync backup

The scripts, below, allow you to sync directories or drives easily. Great for backups.

Save the scripts to text files with the .sh extension. Make them executable (chmod +x).

#!/bin/sh if [ $# -ne 2 ]; then echo 1>&2 "USAGE: /source/dir /backup/dir/" exit 127 fi rsync --delete -av "$1" "$2"

Usage, in terminal window: path/to/ /source/dir/ /backup/dir/. It is recommended to set up, second script below, to execute and supply the arguments for source directory and target backup directory.
Customize the paths to the script, your source directory and the target backup directory.

~/scripts/ /Volumes/sourceDir/ /Volumes/backupDir

Execute the script in a terminal window (drag and drop and hit enter, or enter the path to the script and hit enter), or set up a cron job to execute this script on a schedule.

Important note!
Seems that sometimes we need to run rsync as superuser, to allow the “–delete” flag to do it’s work deleting or moving files that you have deleted or moved on your source directory. So you can run as superuser by typing:

sudo ~/scripts/ /Volumes/sourceDir/ /Volumes/backupDir

I recommend testing these scripts thoroughly, with temporary directories and files, before using them on valuable data!

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/ will open, or create, a file on the Desktop called

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