"""Full Example | |
From https://pyblish.gitbooks.io/pyblish-by-example/content/chapters/02-quickstart.html | |
Usage: | |
Copy and run this entire file in your Maya Script Editor | |
""" | |
import os | |
import shutil | |
from datetime import datetime | |
import pyblish.api | |
import pyblish_maya | |
from maya import cmds | |
# Install Pyblish for Autodesk Maya | |
pyblish_maya.setup() | |
# ---------------------------------------------------------------------------- | |
# | |
# Generate Scene | |
# | |
# ---------------------------------------------------------------------------- | |
cmds.file(new=True, force=True) | |
cmds.polyCube(name="geometry") | |
cmds.sets(name="pointcache_SEL") | |
cmds.circle(name="control") | |
cmds.sets(name="controls_SEL") | |
cmds.select(["geometry", "control"]) | |
cmds.group(name="Bruce_GRP") | |
cmds.select(["Bruce_GRP", "pointcache_SEL", "controls_SEL"], noExpand=True) | |
cmds.sets(name="Bruce_RIG") | |
# Save the scene | |
cmds.file(rename="scene.ma") | |
cmds.file(save=True, type="mayaAscii") | |
# ---------------------------------------------------------------------------- | |
# | |
# Publish | |
# | |
# ---------------------------------------------------------------------------- | |
class CollectRig(pyblish.api.ContextPlugin): | |
"""Discover and collect available rigs into the context""" | |
order = pyblish.api.CollectorOrder | |
def process(self, context): | |
for node in cmds.ls(sets=True): | |
if not node.endswith("_RIG"): | |
continue | |
name = node.rsplit("_", 1)[0] | |
instance = context.create_instance(name, family="rig") | |
# Collect associated nodes | |
members = cmds.sets(node, query=True) | |
cmds.select([node] + members, noExpand=True) | |
instance[:] = cmds.file( | |
constructionHistory=True, | |
exportSelected=True, | |
preview=True, | |
force=True) | |
class ValidateRigContents(pyblish.api.InstancePlugin): | |
"""Ensure rig has the appropriate object sets""" | |
order = pyblish.api.ValidatorOrder | |
families = ["rig"] | |
def process(self, instance): | |
assert "controls_SEL" in instance, "%s is missing a controls set" % instance | |
assert "pointcache_SEL" in instance, "%s is missing a pointcache set" % instance | |
class ExtractRig(pyblish.api.InstancePlugin): | |
"""Serialise valid rig""" | |
order = pyblish.api.ExtractorOrder | |
families = ["rig"] | |
hosts = ["maya"] | |
def process(self, instance): | |
context = instance.context | |
dirname = os.path.dirname(context.data["currentFile"]) | |
name, family = instance.data["name"], instance.data["family"] | |
date = datetime.now().strftime("%Y%m%dT%H%M%SZ") | |
# Find a temporary directory with support for publishing multiple times. | |
tempdir = os.path.join(dirname, "temp", date, family, name) | |
tempfile = os.path.join(tempdir, name + ".ma") | |
self.log.info("Exporting %s to %s" % (instance, tempfile)) | |
if not os.path.exists(tempdir): | |
os.makedirs(tempdir) | |
cmds.select(instance, noExpand=True) # `instance` a list | |
cmds.file(tempfile, | |
type="mayaAscii", | |
exportSelected=True, | |
constructionHistory=False, | |
force=True) | |
# Store reference for integration | |
instance.set_data("tempdir", tempdir) | |
class IntegrateRig(pyblish.api.InstancePlugin): | |
"""Copy files to an appropriate location where others may reach it""" | |
order = pyblish.api.IntegratorOrder | |
families = ["rig"] | |
def process(self, instance): | |
assert instance.data("tempdir"), "Can't find rig on disk, aborting.." | |
self.log.info("Computing output directory..") | |
context = instance.context | |
dirname = os.path.dirname(context.data("currentFile")) | |
root = os.path.join(dirname, "public") | |
if not os.path.exists(root): | |
os.makedirs(root) | |
version = "v%03d" % (len(os.listdir(root)) + 1) | |
src = instance.data("tempdir") | |
dst = os.path.join(root, version) | |
self.log.info("Copying %s to %s.." % (src, dst)) | |
shutil.copytree(src, dst) | |
self.log.info("Copied successfully!") | |
pyblish.api.register_plugin(CollectRig) | |
pyblish.api.register_plugin(ValidateRigContents) | |
pyblish.api.register_plugin(ExtractRig) | |
pyblish.api.register_plugin(IntegrateRig) | |
# Run | |
import pyblish.util | |
pyblish.util.publish() |
This comment has been minimized.
This comment has been minimized.
Thanks for reporting this. This is the intended behaviour, and the reason this is happening is because the plug-in requires Maya but Maya has not been registered with Pyblish. The registration happens automatically with the Pyblish Maya integration, when calling the Here's a guide for this attribute. Note that though gists support comments, they don't support notifications. So feel free to make an issue in the book GitHub project for future problems. I openend up an issue to make this problem more discoverable. |
This comment has been minimized.
This comment has been minimized.
I've updated the file to drop the dependency on the graphical user interface, it now works with just pyblish-base. |
This comment has been minimized.
This comment has been minimized.
Hi, after run this, I got
and I print out the context result, I found
seems lost one line in
after I add this line it worked. Is this fix correct ? Thanks. |
This comment has been minimized.
This comment has been minimized.
Thanks for reporting this. The reason you are seeing this is because you need Pyblish Maya in order to run this example. |
This comment has been minimized.
This comment has been minimized.
Oh I see that, Thanks! |
This comment has been minimized.
This comment has been minimized.
Hi, I'm seeing an Error when running the above code in MAYA 2020, on both OSX and Win10. Runs fine in MAYA 2018 Win10 and MAYA 2019 OSX
|
This comment has been minimized.
This comment has been minimized.
Thanks for reporting this @Jeremyball. Looks like an outdated version of Qt.py, could you try and copy/paste the latest version into that file you see there? If that's the cause, we should be able to update pyblish_maya in the same way and all shall be well. In fact, if it does work you're welcome to copy/paste it into pyblish_maya and submit a PR and fix it for all. |
This comment has been minimized.
When I try to run this on Win7 x64 in Maya2106 I get: