Modulation command, Envelope curves
All  1-4  5-7

Previous
Next
 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
  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:  bemfarmer
5592.6 In reply to 5592.5 
Thank you very much Michael.
The color assignment changes work well.

Edit 12/20/2012, updated script to version2, previous by 2 posts.
Added Michaels color assignment, and added 2 "envelope" curves.

EDITED: 21 Dec 2012 by BEMFARMER

  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:  bemfarmer
5592.7 
Who needs sine waves?
Adapted this technique from Ralf and wave springs on Alibre forum.
Used Epicyhcloid and Hypocycloid speed reducer curves, Lineweb for even number of points, and FreeformThroughPointCurve command.
Then moved the control points along Z axis, and did loft.

Also did another Envelope/Modulation script with sine waves:

EDITED: 24 Jun 2016 by BEMFARMER

Image Attachments:
Size: 126.6 KB, Downloaded: 17 times, Dimensions: 416x251px
Size: 47.3 KB, Downloaded: 11 times, Dimensions: 160x96px
Size: 56.3 KB, Downloaded: 9 times, Dimensions: 160x159px
  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: All  1-4  5-7