Closed davidlatwe closed 6 years ago
Thought this feature(#302) is interesting, did a quick implementation for try out.
Plugins:
Looks great, @davidlatwe! Exactly what I wanted. :)
@mottosso: What do you think?
Thanks guys :D Let me check a bit and bump the version !
Version bumped :) Will merge and release later today !
Thought this feature(#302) is interesting, did a quick implementation for try out.
Plugins:
Example Code
```python import pyblish.api instances = { "Batman": { "family": "hero.human", "category": "Justice League", }, "Superman": { "family": "hero.alien", "category": "Justice League", }, "Spiderman": { "family": "hero.mutant", "category": "Avengers", }, "Ironman": { "family": "hero.human", "category": "Avengers", }, "David": { "family": "hero.human", }, "Wolverine": { "family": "hero.mutant", }, "E.T.": { "family": "hero.alien", }, } class CollectInstances(pyblish.api.ContextPlugin): order = pyblish.api.CollectorOrder def process(self, context): for name, data in instances.items(): instance = context.create_instance(name) instance.data.update(data) context[:] = sorted(context, key=lambda inst: inst.data.get("category", "")) return context class ListInstances(pyblish.api.ContextPlugin): order = pyblish.api.CollectorOrder + 0.1 def process(self, context): for instance in context: self.log.info(instance) class ValidateMutant(pyblish.api.InstancePlugin): order = pyblish.api.ValidatorOrder families = ["hero.mutant"] def process(self, instance): return True class ValidateHuman(pyblish.api.InstancePlugin): order = pyblish.api.ValidatorOrder families = ["hero.human"] def process(self, instance): return True class ValidateAlien(pyblish.api.InstancePlugin): order = pyblish.api.ValidatorOrder families = ["hero.alien"] def process(self, instance): return True pyblish.api.register_plugin(CollectInstances) pyblish.api.register_plugin(ListInstances) pyblish.api.register_plugin(ValidateMutant) pyblish.api.register_plugin(ValidateHuman) pyblish.api.register_plugin(ValidateAlien) ```