Skip to content

pre_windows_console

BlenderConsoleWindows

Bases: PreLaunchHook

Foundry applications have specific way how to launch them.

Blender is executed "like" python process so it is required to pass CREATE_NEW_CONSOLE flag on windows to trigger creation of new console. At the same time the newly created console won't create it's own stdout and stderr handlers so they should not be redirected to DEVNULL.

Source code in client/ayon_blender/hooks/pre_windows_console.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class BlenderConsoleWindows(PreLaunchHook):
    """Foundry applications have specific way how to launch them.

    Blender is executed "like" python process so it is required to pass
    `CREATE_NEW_CONSOLE` flag on windows to trigger creation of new console.
    At the same time the newly created console won't create it's own stdout
    and stderr handlers so they should not be redirected to DEVNULL.
    """

    # Should be as last hook because must change launch arguments to string
    order = 1000
    app_groups = {"blender"}
    platforms = {"windows"}
    launch_types = {LaunchTypes.local}

    def execute(self):
        # Change `creationflags` to CREATE_NEW_CONSOLE
        # - on Windows will blender create new window using it's console
        # Set `stdout` and `stderr` to None so new created console does not
        #   have redirected output to DEVNULL in build
        self.launch_context.kwargs.update({
            "creationflags": subprocess.CREATE_NEW_CONSOLE,
            "stdout": None,
            "stderr": None
        })