Skip to content

project_helpers

activeProject()

hiero.ui.activeProject() -> returns the current Project

Note: There is not technically a notion of a "active" Project in Hiero/NukeStudio, as it is a multi-project App. This method determines what is "active" by going down the following rules...

1 - If the current Viewer (hiero.ui.currentViewer) contains a Clip or Sequence, this item is assumed to give the active Project

2 - If nothing is currently in the Viewer, look to the active View, determine project from active selection

3 - If no current selection can be determined, fall back to a globally tracked last selection from trackActiveProjectHandler

4 - If all those rules fail, fall back to the last project in the list of hiero.core.projects()

@return: hiero.core.Project

Source code in client/ayon_hiero/api/startup/Python/Startup/project_helpers.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def activeProject():
    """hiero.ui.activeProject() -> returns the current Project

    Note: There is not technically a notion of a "active" Project in Hiero/NukeStudio, as it is a multi-project App.
    This method determines what is "active" by going down the following rules...

    # 1 - If the current Viewer (hiero.ui.currentViewer) contains a Clip or Sequence, this item is assumed to give the active Project
    # 2 - If nothing is currently in the Viewer, look to the active View, determine project from active selection
    # 3 - If no current selection can be determined, fall back to a globally tracked last selection from trackActiveProjectHandler
    # 4 - If all those rules fail, fall back to the last project in the list of hiero.core.projects()

    @return: hiero.core.Project"""
    global gTrackedActiveProject
    activeProject = None

    # Case 1 : Look for what the current Viewr tells us - this might not be what we want, and relies on hiero.ui.currentViewer() being robust.
    cv = hiero.ui.currentViewer().player().sequence()
    if hasattr(cv, "project"):
        activeProject = cv.project()
    else:
        # Case 2: We can't determine a project from the current Viewer, so try seeing what's selected in the activeView
        # Note that currently, if you run activeProject from the Script Editor, the activeView is always None, so this will rarely get used!
        activeView = hiero.ui.activeView()
        if activeView:
            # We can determine an active View.. see what's being worked with
            selection = activeView.selection()

            # Handle the case where nothing is selected in the active view
            if len(selection) == 0:
                # It's possible that there is no selection in a Timeline/Spreadsheet, but these views have "sequence" method, so try that...
                if isinstance(hiero.ui.activeView(), (hiero.ui.TimelineEditor, hiero.ui.SpreadsheetView)):
                    activeSequence = activeView.sequence()
                    if hasattr(currentItem, "project"):
                        activeProject = activeSequence.project()

            # The active view has a selection... assume that the first item in the selection has the active Project
            else:
                currentItem = selection[0]
                if hasattr(currentItem, "project"):
                    activeProject = currentItem.project()

    # Finally, Cases 3 and 4...
    if not activeProject:
        activeProjects = hiero.core.projects(hiero.core.Project.kUserProjects)
        if gTrackedActiveProject in activeProjects:
            activeProject = gTrackedActiveProject
        else:
            activeProject = activeProjects[-1]

    return activeProject

openRecentProject(k=0)

hiero.core.openRecentProject(k) -> Opens the most the recent project as listed in the Open Recent list.

@param: k (optional, default = 0) - an integer from 0-4, relating to the index of recent projects. @return: hiero.core.Project

Source code in client/ayon_hiero/api/startup/Python/Startup/project_helpers.py
126
127
128
129
130
131
132
133
134
135
def openRecentProject(k=0):
    """hiero.core.openRecentProject(k) -> Opens the most the recent project as listed in the Open Recent list.

    @param: k (optional, default = 0) - an integer from 0-4, relating to the index of recent projects.
    @return: hiero.core.Project"""

    appSettings = hiero.core.ApplicationSettings()
    proj = appSettings.value('recentFile/%i' % int(k), None)
    proj = hiero.core.openProject(proj)
    return proj

recentProject(k=0)

hiero.core.recentProject(k) -> Returns the recent project path, specified by integer k (0-4)

@param: k (optional, default = 0) - an integer from 0-4, relating to the index of recent projects.

@return: hiero.core.Project

Source code in client/ayon_hiero/api/startup/Python/Startup/project_helpers.py
112
113
114
115
116
117
118
119
120
121
def recentProject(k=0):
    """hiero.core.recentProject(k) -> Returns the recent project path, specified by integer k (0-4)

    @param: k (optional, default = 0) - an integer from 0-4, relating to the index of recent projects.

    @return: hiero.core.Project"""

    appSettings = hiero.core.ApplicationSettings()
    proj = appSettings.value('recentFile/%i' % int(k), None)
    return proj

recentProjects()

hiero.core.recentProjects() -> Returns a list of paths to recently opened projects

Hiero stores up to 5 recent projects in uistate.ini with the [recentFile]/# key.

@return: list of paths to .hrox Projects

Source code in client/ayon_hiero/api/startup/Python/Startup/project_helpers.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
def recentProjects():
    """hiero.core.recentProjects() -> Returns a list of paths to recently opened projects

    Hiero stores up to 5 recent projects in uistate.ini with the [recentFile]/# key.

    @return: list of paths to .hrox Projects"""

    appSettings = hiero.core.ApplicationSettings()
    recentProjects = []
    for i in range(0, 5):
        proj = appSettings.value('recentFile/%i' % i)
        if len(proj) > 0:
            recentProjects.append(proj)
    return recentProjects