API
Search…
Action
Process once, with Context and Plugin as input.
Source
Added
Link
1.2.0
Inherits Plugin

Public Functions

Output
Method

Properties

property
type
icon
str
on
str

Usage

Attach any functionality to a plug-in and tailor it to a particular state; like an action only available via a failed validator, or a successful extraction, or just all-round functionality associated with a particular plug-in.
image
Each action is passed both the Context and it's parent plug-in at run-time and can be accessed via their argument signature, similar to plug-ins.
Actions in QML are arranged in a menu with optional customisable groups and separators. Actions with any kind of implementation error show up as well, including a helpful error message for simplified debugging.
Argument signature
These objects are available via the argument signature.
  • context: The global context
  • plugin: The parent plug-in
Full list of features
  • Per-plugin actions
  • Action API ~= Plug-in API, it is more or less a 1-1 match between their interfaces, including process() and label.
  • Standard logging and exception reporting, identical to plug-ins
  • Customisable icon per action, from Awesome Icon
  • Customisable availability
    • all: Always
    • processed: After plug-in has been processed
    • failed: After plug-in has been processed, and failed
    • succeeded: After plug-in has been processed, and succeeded

Example

1
class OpenInExplorer(pyblish.api.Action):
2
label = "Open in Explorer"
3
on = "failed" # This action is only available on a failed plug-in
4
icon = "hand-o-up" # Icon from Awesome Icon
5
6
def process(self, context, plugin):
7
import subprocess
8
subprocess.call("start .", shell=True) # Launch explorer at the cwd
9
10
11
class Validate(pyblish.api.InstancePlugin):
12
order = pyblish.api.ValidatorOrder
13
actions = [
14
# Order of items is preserved
15
pyblish.api.Category("My Actions"),
16
MyAction,
17
pyblish.api.Separator,
18
]
19
20
def process(self, instance):
21
self.log.info("Standard log messages apply here.")
22
raise Exception("Exceptions too.")
Copied!

Extended Example

Every possible combination of an action.
1
class ContextAction(pyblish.api.Action):
2
label = "Context action"
3
4
def process(self, context):
5
self.log.info("I have access to the context")
6
self.log.info("Context.instances: %s" % str(list(context)))
7
8
9
class FailingAction(pyblish.api.Action):
10
label = "Failing action"
11
12
def process(self, context, plugin):
13
self.log.info("About to fail..")
14
raise Exception("I failed")
15
16
17
class LongRunningAction(pyblish.api.Action):
18
label = "Long-running action"
19
20
def process(self, context, plugin):
21
self.log.info("Sleeping for 2 seconds..")
22
time.sleep(2)
23
self.log.info("Ah, that's better")
24
25
26
class IconAction(pyblish.api.Action):
27
label = "Icon action"
28
icon = "crop"
29
30
def process(self, context, plugin):
31
self.log.info("I have an icon")
32
33
34
class PluginAction(pyblish.api.Action):
35
label = "Plugin action"
36
37
def process(self, context, plugin):
38
self.log.info("I have access to my parent plug-in")
39
self.log.info("Which is %s" % plugin.id)
40
41
42
class LaunchExplorerAction(pyblish.api.Action):
43
label = "Open in Explorer"
44
icon = "folder-open"
45
46
def process(self, context, plugin):
47
import os
48
import subprocess
49
50
cwd = context.data["cwd"]
51
self.log.info("Opening %s in Explorer" % cwd)
52
result = subprocess.call("start .", cwd=cwd, shell=True)
53
self.log.debug(result)
54
55
56
class ProcessedAction(pyblish.api.Action):
57
label = "Success action"
58
icon = "check"
59
on = "processed"
60
61
def process(self, context, plugin):
62
self.log.info("I am only available on a successful plug-in")
63
64
65
class FailedAction(pyblish.api.Action):
66
label = "Failure action"
67
icon = "close"
68
on = "failed"
69
70
71
class SucceededAction(pyblish.api.Action):
72
label = "Success action"
73
icon = "check"
74
on = "succeeded"
75
76
def process(self, context, plugin):
77
self.log.info("I am only available on a successful plug-in")
78
79
80
class BadEventAction(pyblish.api.Action):
81
label = "Bad event action"
82
on = "not exist"
83
84
85
class InactiveAction(pyblish.api.Action):
86
active = False
87
88
89
class PluginWithActions(pyblish.api.InstancePlugin):
90
order = pyblish.api.ValidatorOrder
91
optional = True
92
actions = [
93
pyblish.api.Category("General"),
94
ContextAction,
95
FailingAction,
96
LongRunningAction,
97
IconAction,
98
PluginAction,
99
pyblish.api.Category("OS"),
100
LaunchExplorerAction,
101
pyblish.api.Separator,
102
FailedAction,
103
SucceededAction,
104
pyblish.api.Category("Debug"),
105
BadEventAction,
106
InactiveAction,
107
]
108
109
def process(self, instance):
110
self.log.info("Ran PluginWithActions")
Copied!

Maya Example

1
import time
2
import pyblish.api
3
import pyblish_qml
4
5
6
class Collect(pyblish.api.Collector):
7
def process(self, context):
8
i = context.create_instance("MyInstance")
9
i.data["family"] = "default"
10
i.append("pCube1")
11
12
13
class SelectInvalidNodes(pyblish.api.Action):
14
label = "Select broken nodes"
15
on = "failed"
16
icon = "hand-o-up"
17
18
def process(self, context):
19
self.log.info("Finding bad nodes..")
20
nodes = []
21
for result in context.data["results"]:
22
if result["error"]:
23
instance = result["instance"]
24
nodes.extend(instance)
25
26
self.log.info("Selecting bad nodes: %s" % ", ".join(nodes))
27
cmds.select(deselect=True)
28
cmds.select(nodes)
29
30
31
class Validate(pyblish.api.Validator):
32
actions = [
33
pyblish.api.Category("Scene"),
34
SelectInvalidNodes
35
]
36
37
def process(self, instance):
38
raise Exception("I failed")
39
40
41
pyblish.api.register_plugin(Collect)
42
pyblish.api.register_plugin(Validate)
43
44
import pyblish_maya
45
pyblish_maya.show()
Copied!
{{ file.mtime }}
Last modified 1yr ago