Filtering
Filtering is handy when more control over your plugins is needed.
After registering a callback function, it'll run on all registered plugins during discovery. This is useful to overwrite the settings of registered plugins.
For example, here's how we can overwrite a hardcoded export path so as to reuse a plugin for another project, without having to write and register a new plugin.
1
import pyblish.api
2
3
# The original plug-in
4
class MyExportPlugin(pyblish.api.ContextPlugin):
5
export_path = "C:/project_alpha/models"
6
def process(self, context):
7
print("Exported to: '%s'" % self.export_path)
8
9
pyblish.api.register_plugin(MyExportPlugin)
10
11
# Our custom "filter"
12
def export_path_filter(plugins):
13
for plugin in plugins:
14
if hasattr(plugin, 'export_path'):
15
plugin.export_path = 'D:/project_beta/models'
16
17
pyblish.api.register_discovery_filter(export_path_filter)
18
19
import pyblish.util
20
pyblish.util.publish()
21
# Exported to 'to:D:/project_beta/models'
Copied!
You can register a filter using api.register_discovery_filter.
Note that functions stay registered and won't update when you re-register them with the same name. You have to either deregister the original one, or use pyblish.api.deregister_all_discovery_filters() to unregister all filters.
Last modified 1mo ago
Copy link