Pyblish By Example
1.8
1.8
  • Introduction
  • Hello World
  • Quickstart
  • Files
  • Coordination
  • Architecture
  • Branching I
  • Branching II
  • Branching III
  • Sharing
  • Validating I
  • Validating II
  • CVEI I
  • CVEI II
  • CVEI III
  • CVEI IV
  • Data
  • Report I
  • Report II
  • Report III
  • Report IV
  • Report V
  • Callback I
  • Callback II
  • Callback III
  • Logging
  • Filtering
  • Next Steps
Powered by GitBook
On this page

Was this helpful?

Validating I

Sometimes, sharing means to first agree on a format in which to share, such that you don't end up with one big mess.

import pyblish.api

items = ["JOHN.person", "door.prop"]

class CollectInstances(pyblish.api.ContextPlugin):
  order = 0

  def process(self, context):
    for item in items:
      name, suffix = item.split(".")
      context.create_instance(name, family=suffix)

class ValidateNamingConvention(pyblish.api.InstancePlugin):
  order = 1

  def process(self, instance):
    name = instance.data["name"]
    assert name == name.title(), "Sorry, %s should have been %s" % (
      name, name.title())

pyblish.api.register_plugin(CollectInstances)
pyblish.api.register_plugin(ValidateNamingConvention)

import pyblish.util
pyblish.util.publish()
# Sorry, JOHN should have been John
# Sorry, door should have been Door
Stopped due to: failed validation

We indicate failure by throwing exceptions of any kind, including assertions. Making the change, we now "pass validation".

...
items = ["John.person", "Door.prop"]
...
pyblish.util.publish()
# John is valid
# Door is valid
PreviousSharingNextValidating II

Last updated 5 years ago

Was this helpful?