API
Search…
Context
The context represents the world.
Source
Added
Link
0.1.6
Inherits AbstractEntity

Public Functions

Output
Method
Instance
.create_instance(str, **kwargs)
4 functions inherited from AbstractEntity

Description

The context encapsulates one or more Instance's along with information about the current execution environment, such as the current user and time of day. Publishing is performed by iterating over the members of a context.
1
# Psuedo-code
2
for plugin in plugins:
3
for instance in context:
4
plugin.process(instance)
Copied!

Examples

1
# Creating a context
2
#
3
# The context is normally created for you by a user interface or
4
# through convenience functions, but can be helpful to manually
5
# create for debugging purposes.
6
7
import pyblish.api as pyblish
8
context = pyblish.Context()
Copied!
1
# Creating instances from a context
2
#
3
# Instances can be created directly or through a context. When
4
# created through a context, the context is automatically set
5
# as the parent of the newly created instance.
6
7
import pyblish.api as pyblish
8
context = pyblish.Context()
9
instanceA = context.create_instance(name="MyInstanceA")
10
instanceB = pyblish.Instance(name="MyInstanceB", parent=context)
11
12
print("The context contains these instances:")
13
for instance in context:
14
print(instance)
15
# MyInstanceA
16
# MyInstanceB
Copied!
1
# Setting data on a context
2
#
3
# Both Instance and Context inherit from AbstractEntity which
4
# provides the mechanism for modifying data.
5
6
import pyblish.api as pyblish
7
context = pyblish.Context()
8
data = context.data
9
context.data["hostname"] = "localhost"
10
assert "hostname" in context.data is True
11
context.data.pop("hostname")
12
assert "hostname" in context.data is False
Copied!
{{ file.mtime }}
Last modified 1yr ago