How to merge an expression


I try to create an expression to particles with the command dynExpression, like this:

dynExpression -c -s "identite=trunc(rand(1,3));" $nom_part;

But it’s replace the existing creation expression in the particleShape.

It is possible to “merge” my expression after the existing expression?


You have to use the + operator.
For example:

 expression -s ("$herdvar = "+ (rand(1) - 0.5) +" * "+$leader+".rnds + "+$objnum+";
 + "$randfac = " + $leader + ".stry;
 + "$foc = "+$leader+".lf;
" );


Thank’s drGonzo, but now how I can save the existing expression in a variable to add my expression after?


Like so:

string $Expression = `dynExpression -c -s "mass=trunc(rand(1,3))

if you need inspiration for a good expression script, dissect SnowMaker. You can find it at he3D.


thank a lot drGonzo


I’m not sure that DrGonzo’s scripts do what you want.

What you’ll need to do is get the existing expression using dynExpression -q (to query it) and then add your existing expression to the end with +, then use dynExpression like you already have to put the merged expression back in.

At least, I think that will work, assuming dynExpression -q does what I think it does.

– Mark


Aha. The Master put me on the right track :wink:

Like this then:

  //put an expression in editor
  string $originalExpression = `dynExpression -c -s "particleShape1.mass=trunc(rand(1,3));
  //put additional expression in variable
  string $additionalExpression= "particleShape1.lifespanPP=rand(1,3);
  //query content of creation expression
  string $creationContent = `dynExpression -q -c`;
  //compile result of query and additional expression 
  string $compiledExpression = $creationContent +  $additionalExpression;
  //print $compiledExpression;
  //put compilation in editor
  dynExpression -c -s $compiledExpression; 


Yes it’s work :slight_smile:

Thank you for your help.


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.