Can update Particle during mel runnig?

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
  03 March 2013
How to update Particle during mel runnig?

Hi, all.

I'm just learning mel and try to write one, which can convert objects to nParticle with Instancer.
Here is my scenario :

  1. select the objs which I want to convert to nParticle
  2. born nP at those obj's ScalePivot
  3. assign a Instancer use those objs
  4. enable "Comput Rotation"
  5. set rotationPP to Rotation of Instancer (and other setting)
The problem happen between step 4~5. even the mel enabled "ComputeRotation", rotationPP didn't appear(create) in the Per Particle(Array) Attribute editor until I select nParticleShape by manual. RotationPP are not created so can't set it to Rotation of Instancer.

If I do like this that mel will work :

  1. run mel 1,2,3 and 4 step, don't run 5
  2. select nParticleShape by hand, so that it can update
  3. run the final step 5
except rotationPP this mel is fine.

How can I run mel and update the nParticle at same time? Could someone give a idea, please?

thank you : )


//======= below is my code, the problem code are marked by "***".

//global proc O2Ptool(){
//select all obj
string $sel[] = `ls -sl`;
string $creatP = "nParticle -n tempNP";
int $count = `size($sel)`;
for( $i=0 ; $i < $count; $i++)
xform -cp $sel[$i];
vector $pos = `xform -q -ws -sp $sel[$i]`;
$creatP += (" "+"-p"+" "+$pos) ;
eval $creatP ;
addAttr -ln radiusPP -dt doubleArray tempNPShape;
addAttr -ln radiusPP0 -dt doubleArray tempNPShape;
// setAttr "tempNPShape.computeRotation" 1;

//set boundingBoxSize to radiusPP
for($i= 0; $i < $count ; $i++)
string $bx = $sel[$i] + ".boundingBoxSizeX";
float $x = `getAttr $bx`;
string $by = $sel[$i] + ".boundingBoxSizeY";
float $y = `getAttr $by`;
string $bz = $sel[$i] + ".boundingBoxSizeZ";
float $z = `getAttr $bz`;
float $rPP = ( $x+ $y+ $z )* .12;
particle -e -or $i -at radiusPP0 -fv $rPP tempNPShape ;

//create a new shader
shadingNode -asShader lambert -n tempM;
sets -renderable true -noSurfaceShader true -empty -name tempSG;
connectAttr -f tempM.outColor tempSG.surfaceShader;
float $CR = rand(1);
float $CG = rand(1);
float $CB = rand(1);
setAttr "tempM.color" -type double3 $CR $CG $CB ;

//copy obj into new group
select $sel;

duplicate -rr -n "temp1";
group -w -n instansSource1;
xform -os -piv 0 0 0;
string $tt[0] = `ls -sl`;

//move obj to original and freeze
string $instancer = "particleInstancer -n tempInst -a";
select -hi;
select -d $tt[0] ;
string $sel2[] = `ls -sl -tr`;

for($temp in $sel2)
select $temp;
xform -cp;
move -a -ws -rpr 0 0 0;
channelBoxCommand -freezeAll;
sets -e -forceElement tempSG;
$instancer += " -obj "+ $temp;

//assign instancer
$instancer += " -position worldPosition -objectIndex particleId -age age tempNPShape";
print $instancer;
eval $instancer;

setAttr "tempNPShape.computeRotation" 1;
select tempNPShape;
//********************************** Here is the Problem step *************

particleInstancer -e -name tempInst -r rotationPP tempNPShape;

//************************************************** ******************************
// setAttr tempNPShape.particleRenderType 3;
rename tempNP nParticle1;
rename tempInst instancer1;
//rename SG
rename tempM lamdert1;
rename tempSG lambertSG;

//hide source objs
for ($temp in $sel)
string $hi = "setAttr "+ $temp + ".visibility 0";
eval $hi;
//hide instancer
string $hi = "setAttr "+ $tt[0] + ".visibility 0";
eval $hi;
for($temp in $sel2)
rename $temp "source1";

Last edited by igou : 03 March 2013 at 02:02 AM.
  03 March 2013
You can just add these attributes trough script before setting the "compute rotation" checkbox:

addAttr -ln rotationPP -dt vectorArray nParticleShape1;
 addAttr -ln rotationPP0 -dt vectorArray nParticleShape1;
..aut inveniam viam aut faciam..
::Copy SOP 4 Maya::
  03 March 2013
Cool! it fixed!! I don't know I can create this attribute by hand to avoid ...XD
Thank you, Azrail : D
  03 March 2013
Hi, Azrail.
Cool ! your way is worked, it was fixed!! So create attribute by manual can avoid this kind problem, learned it !
Thank You : D
  03 March 2013
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 07:54 AM.

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