Skip to content

set_context_placeholder

Set Context Placeholder Plugin for Blender Workfile Build.

SetContextBlenderPlaceholderPlugin

Bases: BlenderPlaceholderPlugin

Set context variables for the workfile build. This placeholder allows the workfile build process to set context variables dynamically.

Source code in client/ayon_blender/plugins/workfile_build/set_context_placeholder.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class SetContextBlenderPlaceholderPlugin(BlenderPlaceholderPlugin):
    """Set context variables for the workfile build.
    This placeholder allows the workfile build process to
    set context variables dynamically.

    """

    identifier = "blender.set_context"
    label = "Set Context Settings"

    use_selection_as_parent = False

    def get_placeholder_options(self, options=None):
        options = options or {}
        return [
            BoolDef(
                "resolution",
                label="Set Resolution",
                tooltip="Set Resolution context variable "
                        "based on the scene settings",
                default=options.get("resolution", True),
            ),
            BoolDef(
                "frame_range",
                label="Set Frame Range",
                tooltip="Set Frame Range context variable "
                        "based on the scene settings",
                default=options.get("frame_range", True),
            ),
            BoolDef(
                "scene_units",
                label="Set Scene Units",
                tooltip="Set Scene Units context variable "
                        "based on the scene settings",
                default=options.get("scene_units", False),
            )
        ]

    def populate_placeholder(self, placeholder):
        self.set_context_settings(placeholder)
        if not placeholder.data.get("keep_placeholder", True):
            self.delete_placeholder(placeholder)

    def set_context_settings(self, placeholder):
        """Set context settings for the placeholder.

        Args:
            placeholder (dict): placeholder data
        """
        placeholder_context_data = {
            "resolution": placeholder.data.get("resolution", True),
            "frame_range": placeholder.data.get("frame_range", True),
            "scene_units": placeholder.data.get("scene_units", False),
        }
        set_context_settings(**placeholder_context_data)

set_context_settings(placeholder)

Set context settings for the placeholder.

Parameters:

Name Type Description Default
placeholder dict

placeholder data

required
Source code in client/ayon_blender/plugins/workfile_build/set_context_placeholder.py
52
53
54
55
56
57
58
59
60
61
62
63
def set_context_settings(self, placeholder):
    """Set context settings for the placeholder.

    Args:
        placeholder (dict): placeholder data
    """
    placeholder_context_data = {
        "resolution": placeholder.data.get("resolution", True),
        "frame_range": placeholder.data.get("frame_range", True),
        "scene_units": placeholder.data.get("scene_units", False),
    }
    set_context_settings(**placeholder_context_data)