Modulation command, Envelope curves

 From:  Michael Gibson
5592.5 In reply to 5592.4 
Hi Brian,

> Is there a better way to assign colors to factory/factories/arrays, in scripts?

Well colors do come from style assignments so to modify them you do need to assign styles like you're doing.

One change you could though would be to only modify styles just on the objects that you are generating instead of other things too.

Right now in the color assignment step, you've got:

var curves = moi.geometryDatabase.getObjects().getCurves();

So that will go get a list of every curve that's in the entire geometry database, even ones that had nothing to do with your current generated ones.

Instead try something like:

var curves = factory.getCreatedObjects();

That should then get you a list of all objects that were generated by that particular factory after it was updated.


You might want to make a helper function at the top something like this:

code:
var g_style_index = 1;

function AssignColors( factory )
{
	var styles = moi.geometryDatabase.getObjectStyles();
	var curves = factory.getCreatedObjects();
	for ( var i = 0; i < curves.length; ++i, ++g_style_index )
	{
		if ( g_style_index == styles.length )
		{
			g_style_index = 0;
		}
		var curve = curves.item(i);
		curve.styleIndex = g_style_index;
	}
}


Then you could modify your other places to call it like this:

code:
        <.....>

//	Three factory(s) to update.
	for ( var k = 0; k < Sfactory.length; ++k )
	{
		Sfactory[k].update();
		AssignColors( Sfactory[k] );
	}
	for ( var k = 0; k < Cfactory.length; ++k )
	{
		Cfactory[k].update();
		AssignColors( Cfactory[k] );
	}
	for ( var k = 0; k < AModfactory.length; ++k )
	{
		AModfactory[k].update()
		AssignColors( AModfactory[k] );
	}



Hope this helps!

- Michael