-
-
Save mottosso/93399862c94f0ab4314f to your computer and use it in GitHub Desktop.
"""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() |
Running from PyCharm with mayapy.exe (2022) as the interpreter, pyblish-base and pyblish-maya installed, I get the following when running this script:
Traceback (most recent call last): File "C:\Program Files\Autodesk\Maya2022\Python37\lib\code.py", line 90, in runcode exec(code, self.locals) File "<input>", line 1, in <module> File "C:\Users\frost\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\222.4167.33\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "C:\Users\frost\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\222.4167.33\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:\dev\tech-art\maya-toolkit-dev\src\scripts\pforest\pyblish_tests\rig_example.py", line 12, in <module> import pyblish_maya File "C:\Users\frost\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\222.4167.33\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\pyblish_maya\__init__.py", line 1, in <module> from version import * File "C:\Users\frost\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\222.4167.33\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) ModuleNotFoundError: No module named 'version'
I should note that simply attempting to import pyblish-maya yields the same result.
This looks like a Python 3 issue, and I would double-check you've got the latest current version of pyblish-maya, because this one does appear to work.
You can install directly from GitHub with..
pip install git+https://github.com/pyblish/pyblish-maya.git
I fix this issue by replacing
QStringListModel
bystr
in this form_remap(QtCore, "QStringListModel", str)