This section contains information about advanced scripting in Pixyz Studio.


Filter expressions let you run a single Python call for multiple operations in the Pixyz Core module.


This example show how you can use filter expressions:


# Without filter expressions: n * execution time of core.getProperty

names = list()


for occurrence in scene.findByProperty('Name', '.*'): # scene.findByProperty('Name', '.*') returns all scene occurrences

       names.append(core.getProperty(occurrence, 'Name'))


# With filter expressions: one call for multiple operations


names = scene.evaluateExpressionOnSubTree('Property("Name")', scene.getRoot())

Types


An expression returns a value that is of one of these types:

  • None
  • Entity – an entity may be an occurrence, a component, a material…
  • String
  • Numeric
  • Boolean


Functions


You can use these functions:


  • Boolean String.Matches(String regexp)
  • String Entity.Property(String propertyName)
  • Boolean Entity.SetProperty(String propertyName, String propertyValue) 
  • Occurrence Occurrence.Parent()
  • Entity Occurrence.Component(String componentType)
  • Boolean This.IsNone()
  • Numeric This.ToNumeric()



All functions apply to an object. This code block shows an example:


# Filters all occurrences containing "Hello" in the property "Name"

# Property returns a String and applies on an Occurrence

# Matches applies on an Occurrence and returns a Boolean

Property('Name').Matches('.*Hello.*')

Logical operators


You can use these logical operators: 


Logical operator

Example

Result

AND

Expr = Expr1 OR Expr2

If Expr1 == true, returns eval(Expr1). Otherwise, returns eval(Expr2).

OR

Expr = Expr1 AND Expr2

If Expr1 == false, returns eval(Expr1). Otherwise, returns eval(Expr2).

Examples


  • Hide all unselected occurrences:

selection = scene.getSelectedOccurrences()

scene.evaluateExpressionOnOccurrences(selection, 'SetProperty("Visible", "Inherited")')

scene.invertSelection()

unselected = scene.getSelectedOccurrences()

scene.evaluateExpressionOnOccurrences(unselected, 'SetProperty("Visible", "False")')

scene.clearSelection()

scene.select(selection)


  • Select all occurrences whose parent has a material whose name contains "8":

filter = 'Parent().Property("Material") AND Parent().Property("Material").Property("Name").Matches(".*8.*")'

occs = scene.getFilteredOccurrences(filter)

scene.select(occs)