Filter Expressions
How to use filter expressions for advanced Python scripting in Asset Transformer Studio
읽는 시간 1분최근 업데이트: 21일 전
Filter expressions let you run a single Python call for multiple operations in the Core module.
This example shows how you can use filter expressions:
## Without filter expressions: n * execution time of core.getProperty names = list() for occurrence in scene.findOccurrencesByProperty('Name', '.*'): 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 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
Logical operator | Example | Result |
|---|---|---|
| AND | | If |
| OR | | If |
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)