CVEI II
Sometimes the file-management part of extraction is better kept separate.
In this example, we will:
  1. 1.
    Simulate an Autodesk Maya environment
  2. 2.
    Extract some data from it
  3. 3.
    Integrate this data with a server
  4. 4.
    Without making reference to the simulated environment
Our environment.
1
import sys
2
3
disk = {}
4
server = {}
5
6
class cmds:
7
@staticmethod
8
def ls(type, assemblies):
9
return maya.scene.keys()
10
11
@staticmethod
12
def file(path, exportSelected):
13
disk[path] = maya.scene[maya.selected]
14
15
@staticmethod
16
def select(node):
17
maya.selected = node
18
19
class maya:
20
selected = None
21
cmds = cmds
22
scene = {
23
"john": 0xb3513451, # Binary
24
"door": 0x516b481f,
25
}
26
27
sys.modules["maya"] = maya
Copied!
We can now from maya import cmds, which we will use during collection and extraction.
1
import pyblish.api
2
from maya import cmds
3
4
class CollectInstances(pyblish.api.ContextPlugin):
5
order = pyblish.api.CollectorOrder
6
7
def process(self, context):
8
for name in cmds.ls(type="transform", assemblies=True):
9
context.create_instance(name)
10
11
class ExtractInstances(pyblish.api.InstancePlugin):
12
order = pyblish.api.ExtractorOrder
13
14
def process(self, instance):
15
# 1. Compute temporary output path
16
name = instance.data["name"]
17
transient_path = "c:\temp\%s.mb" % name
18
19
# 2. Perform serialisation
20
cmds.select(name)
21
cmds.file(transient_path, exportSelected=True)
22
23
# 3. Store reference for subsequent plug-ins
24
instance.data["transientDest"] = transient_path
Copied!
Now let's integrate the data from temp on disk into our server.
1
class IntegrateInstances(pyblish.api.InstancePlugin):
2
3
order = pyblish.api.IntegratorOrder
4
5
def process(self, instance):
6
transient_dest = instance.data["transientDest"]
7
permanent_dest = "/instances/%s.mb" % instance
8
server[permanent_dest] = disk[transient_dest]
Copied!
Putting it all together, this is the full source code.
1
import sys
2
3
disk = {}
4
server = {}
5
6
class cmds:
7
@staticmethod
8
def ls(type, assemblies):
9
return maya.scene.keys()
10
11
@staticmethod
12
def file(path, exportSelected):
13
disk[path] = maya.scene[maya.selected]
14
15
@staticmethod
16
def select(node):
17
maya.selected = node
18
19
class maya:
20
selected = None
21
cmds = cmds
22
scene = {
23
"john": 0xb3513451, # Binary
24
"door": 0x516b481f,
25
}
26
27
sys.modules["maya"] = maya
28
29
import pyblish.api
30
from maya import cmds
31
32
class CollectInstances(pyblish.api.ContextPlugin):
33
order = pyblish.api.CollectorOrder
34
35
def process(self, context):
36
for name in cmds.ls(type="transform", assemblies=True):
37
context.create_instance(name)
38
39
class ExtractInstances(pyblish.api.InstancePlugin):
40
order = pyblish.api.ExtractorOrder
41
42
def process(self, instance):
43
# 1. Compute temporary output path
44
name = instance.data["name"]
45
transient_path = "c:\temp\%s.mb" % name
46
47
# 2. Perform serialisation
48
cmds.select(name)
49
cmds.file(transient_path, exportSelected=True)
50
51
# 3. Store reference for subsequent plug-ins
52
instance.data["transientDest"] = transient_path
53
54
class IntegrateInstances(pyblish.api.InstancePlugin):
55
order = pyblish.api.IntegratorOrder
56
57
def process(self, instance):
58
transient_dest = instance.data["transientDest"]
59
permanent_dest = "/instances/%s.mb" % instance
60
server[permanent_dest] = disk[transient_dest]
61
62
63
pyblish.api.register_plugin(CollectInstances)
64
pyblish.api.register_plugin(ExtractInstances)
65
pyblish.api.register_plugin(IntegrateInstances)
66
67
import pyblish.util
68
pyblish.util.publish()
69
print disk
70
print server
71
# {'c:\temp\\john.mb': 3008443473L, 'c:\temp\\door.mb': 1365985311}
72
# {'/instances/john.mb': 3008443473L, '/instances/door.mb': 1365985311}
Copied!
The key point to take away from this example is that file-management is independent of serialisation.
Last modified 1yr ago
Copy link