Background Image Script?

 From:  FDP
6162.29 In reply to 6162.28 
Hi Michael,
I was wondering if you might be able to give some advice/help. I integrated the branching you recommended (which works perfectly), but now am trying to make the layers position themselves at a z depth matching the image number. I've stolen what seems like 99% of the right code from the "Nudge" script. I think the problem is with using the "factory.setInput( 0, obj );" where "obj" is an object selected by being unnamed. Here's the snippet:

function SetObjectNames( newname )
{
// Set any unnamed objects to have the given name.

var objects = moi.geometryDatabase.getObjects();

for ( var i = 0; i < objects.length; ++i )
{
var obj = objects.item(i);

// An "unnamed" object will have an empty string as its name property.
if ( obj.name == '' )
obj.name = newname;

// Set the selected object to a Z plane derived from the layer/frame#
// Stolen verbatim from the "nudge" script.
var factory = moi.command.createFactory( 'move' );
factory.setInput( 0, obj );
var axis = 'zaxis';
var dist = 1.0;

// Create 2 points, these will default to 0,0,0.
var basept = moi.vectorMath.createPoint();
var offsetpt = moi.vectorMath.createPoint();

// Set up the offset point.
var dir = moi.view.getCPlane()[axis];
dir.scale( dist );
offsetpt.add( dir );

factory.setInput( 1, basept );
factory.setInput( 2, offsetpt );
factory.commit();

}
}

I've attached the version of the script that the snippet came from which isn't working (v4) as well as the last version that works (v3).

To use the script just call it with "inc" or "dec" as a parameter. I have these hotkeyed to "CTRL +" and "CTRL -" on my keyboard, and version 3 works very nicely!

-FDP