Author Topic: create a variable for the "SelectExpressionModifier"  (Read 172 times)

dark_knight

  • Newbie
  • *
  • Posts: 4
create a variable for the "SelectExpressionModifier"
« on: June 21, 2019, 05:44:04 PM »
Hi
I want to have a variable in the "SelectExpressionModifier", something like this:
expression ='variable1<Position.X<variable2'
I know that there is the same topic in http://forum.ovito.org/index.php?topic=170.msg387#msg387, but i cannot understand very well and my python code still has errors. I could not Inject the Python value into OVITO's data pipeline as a new global attribute by:
      def modify(frame, input, output):
          output.attributes['variable1'] =variable1
          output.attributes['variable2'] =variable2
Thanks

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 638
Re: create a variable for the "SelectExpressionModifier"
« Reply #1 on: June 22, 2019, 10:44:15 PM »
Hi,

You can use the '&&' operator (logical AND operator) to test whether a value is between a lower and an upper bound:

"variable1 < Position.X && Position.X < variable2"

This expression will evaluate to true if and only if both sub-expressions are true.

Regarding you second question I am not sure what is going wrong. The modify() function you posted looks okay. Maybe you are doing things in the wrong order? The Python modifier function must be inserted into the pipeline before the SelectExpressionModifier so that the two attributes are available when the Boolean expression refers to them. Please attach the entire script code if you can't get it working.

-Alex