PDA

View Full Version : query particle shape within expression


splinta
12-07-2012, 08:12 AM
Hi all

So I'm building a script to generate some particles etc. and I found that I needed to some how query a particle shape name to plug into a variable with in a creation expression. or any expression really.

The expression I was trying to generate is:
int $customIndex = rand(0,4);
nParticleShape1.customIndex = $customIndex;


Pretty simple stuff but I need to make the expression generic to fit whatever name changes may occur with the particleShape.

I'm sure this is a simple issue to fix but my mel scripting knowledge is limited.

Any help would be appreciated.

eebling
12-08-2012, 11:00 PM
as long as you know the particle node name you can use" listRelatives -s" to find out the shape name. Here is a super simple example code
{

string $particle[] = `ls -sl`;

string $particleShape[] = `listRelatives -s $particle`;

print $particleShape;

}

if you create a particle shape, just select it and run this in the script editor and it will print the particles shape name.

splinta
12-11-2012, 06:13 AM
Thanks for the reply.

In a normal situation that would work just fine. However, I need to get the particle shape name independently of what is selected. As the expression will run everytime I hit play.

I thought about naming the expression something specific and then querying the link between them to get the shape name but I dont know the code syntax to do this.

Also the scene may have any number of particle sytems running so I them to query themselves specifically without the others getting in the way.

any help?

as long as you know the particle node name you can use" listRelatives -s" to find out the shape name. Here is a super simple example code
{

string $particle[] = `ls -sl`;

string $particleShape[] = `listRelatives -s $particle`;

print $particleShape;

}

if you create a particle shape, just select it and run this in the script editor and it will print the particles shape name.

Azrail
12-11-2012, 09:18 AM
Particle shape name is added to your code by the program whenever you close the expressions editor, and you can't do nothing about it. But since you can use only attribute names in you expression when you create it, like this:

rgbPP = 1;
radiusPP = age/lifespanPP;
velocity = dnoise(position);

then the expression itself is generic enough.
What you can do is write a simple procedure, which gets the desired expression, which will already include the shape name, and than remove all occurrences of the shape's name, thus converting it back to generic one. Actually here you go:

global proc ntGenericDynExp(string $shape)
{
// Creation
string $creation = `dynExpression -q -creation $shape`;
string $creationGen = substituteAllString($creation, $shape+".", "");
string $sep = "\n\n=========================================================================\n\n";

// Runtime Before
string $runbefore = `dynExpression -q -rbd $shape`;
string $runbeforeGen = substituteAllString($runbefore, $shape+".", "");

// Runtime After
string $runafter = `dynExpression -q -rad $shape`;
string $runafterGen = substituteAllString($runafter, $shape+".", "");

if (`window -q -ex gdexWin`) deleteUI gdexWin;
window gdexWin;
$tabs = `tabLayout`;
$scroll1 = `scrollField -tx ($creation + $sep + $creationGen) -p $tabs`;
$scroll2 = `scrollField -tx ($runbefore + $sep + $runbeforeGen) -p $tabs`;
$scroll3 = `scrollField -tx ($runafter + $sep + $runafterGen) -p $tabs`;
tabLayout -e
-tl $scroll1 "Creation"
-tl $scroll2 "Runtime Before"
-tl $scroll3 "Runtime After" $tabs;
showWindow gdexWin;
}

ntGenericDynExp nParticleShape1;


You can of course modify that in order to directly assign the expression to another node, operate on multiple selected nodes and whatnot. The only problem is that you might have some issues with escapable characters like quotes, newlines and the sort when you try to assign the 'generic' one to a new shape, but that should be tested. Also bear in mind that trying to assign the expression will raise error if you use custom dynamic attributes, which are not present in the target particle shape;

EDIT: powered by p, li { white-space: pre-wrap; }

CGTalk Moderation
12-11-2012, 09:18 AM
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.