randomly select children?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  09 September 2005
randomly select children?

Is there a function, plugin, coffee expression or xpreso setup in existance that will randlmly select a percentage of children in a heirarchy? Something I need immediately for a project I'm wrapping up.

  09 September 2005
Here's a simple 9.5 script

// Get the active object
var op = doc->GetActiveObject();
if(!op) return;

// De-select all objects first

// Percentage  0.0 = 0%, 1.0 is 100%
var perc = 0.5;

// Get te first child object of active object
var child = op->GetDown();

// Start random generator
var r = new(Random);
var n;

// Count the children
 // Generate a number between 0.0 and 1.0
 n = r->Get01();
 // Is this number less than our percentage?
 if(n < perc)
	  // Select object
		// Update object

 // Move onto next object
 child = child->GetNext();


// Update document

Just add it to the Script Manager, select a parent object and execute the script the usual method.

Latest Plugin: GroupConnect
  09 September 2005
if you're using 9.5 you can whip up a little coffee expression in no time

it should be something like:

   //recursive select routine
   Rselect(op,rnd) {
   	//randomly select (make active or not)
   	if (rnd->Get11()>0.0) op->SetBit(BIT_AOBJ);
   	else op->DelBit(BIT_AOBJ);
   	//recurse through hierarchy
   	var nchild=op;
   	for (nchild=nchild->GetDown();nchild;nchild=nchild->GetNext()) Rselect(nchild,rnd);
   //main function routine
   main(doc,op) {
   	var child=op->GetDown();
   	var random_seed=123456;
   	var rnd=new(Random);
   	//init random number generator with seed
   	for (child=op->GetDown();child;child=child->GetNext()) Rselect(child,rnd);
   	return TRUE;

[edit] oops, geespot beat me to it

anyhow, this can work as a coffee tag too in theory (though it may slow down everything to hell)[/edit]
The Third Party | Homepage | My Reel
"You need to know what you're doing before you start, and to start because you need what you're doing."

Last edited by mdme_sadie : 09 September 2005 at 07:18 PM.
  09 September 2005
Thanks guys.

I figured it would be a 9.5 coffee thing.

(copy -paste, copy paste)

I'm in 9.1 at the moment--but once I install I see this shouldnt be a problem. And also thanks to the guys who PM'd me as well.
  09 September 2005
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 09:58 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.