randomly select children?

Become a member of the CGSociety

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

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 09 September 2005   #1
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.

Thanks!
 
Old 09 September 2005   #2
Here's a simple 9.5 script

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

// De-select all objects first
CallCommand(12113);

// 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);
r->Init(GeGetSysTime()->second);
var n;

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

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

}

// Update document
doc->Message(MSG_UPDATE);


Just add it to the Script Manager, select a parent object and execute the script the usual method.
__________________
http://www.iangorse.co.uk/

Latest Plugin: GroupConnect
 
Old 09 September 2005   #3
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
   	rnd->Init(random_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.
 
Old 09 September 2005   #4
hehe
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.
 
Old 09 September 2005   #5
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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

All times are GMT. The time now is 10:05 PM.


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