Background Image Script?
 1-8  9-28  29-32

Previous
Next
 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

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
6162.30 In reply to 6162.29 
Hi FDP,

> 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:

From my first quick look, it looks like you need to make an "object list" to put into the factory's input index 0, not just an object.

Someday I'd like to tune this up so that the factory system could take either a single object or an object list in that slot but right now it usually only expects to see object lists there for factories that can take more than one object for their operations.

So try something like this - above your function SetObjectNames put in this function:

code:
function WrapWithObjectList( obj )
{
	// Create an object list and fill it with the given object. Some things require an object
	// list for input and can't handle a single object instead right now.
	var list = moi.geometryDatabase.createObjectList();
	list.addObject( obj );
	return list;
}


And then inside your function change:
code:
factory.setInput( 0, obj );


to instead be:

code:
factory.setInput( 0, WrapWithObjectList(obj) );


At some point I also expect to make some more friendly direct calls for things like copying and transforming objects and making lines and things like that, rather than only having the factory type methods... The factory mechanism works well for interactive commands since you can hook things like a pointpicker into a factory input and then that drives updates to that point value, but it's not very convenient when you just want to do a simple transform like you're doing here.

Let me know if you're still running into problems after that change and I'll take a close look.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  FDP
6162.31 In reply to 6162.30 
Thanks Michael! This has gotten to be pretty awesome pretty quickly. I've added in the layer movement and set it up so it moves layers forwards or backwards along with the image sequence position (might get really slow with a large amount of curves). This means that whatever image in the sequence is selected will always be at Z = 0.

Attached is the latest version of the script. Now I just need to figure out how to hide layers after they are renamed (assuming I can just use obj.hidden = true;) , as I think this would be helpful as an option!

-FDP
Attachments:

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  Michael Gibson
6162.32 In reply to 6162.31 
Hi FDP, you're welcome!

> (assuming I can just use obj.hidden = true;)

Yup, if you have an object you set it to be hidden by doing: obj.hidden = true.

Also if you have an object list you can set all objects in the list to be hidden by: objlist.setProperty( 'hidden', true );

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

 
 
Show messages:  1-8  9-28  29-32