-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
scene_operation_tk-substancedesigner.py
81 lines (60 loc) · 2.35 KB
/
scene_operation_tk-substancedesigner.py
1
2
3
4
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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Copyright (c) 2013 Shotgun Software Inc.
#
# CONFIDENTIAL AND PROPRIETARY
#
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
# Source Code License included in this distribution package. See LICENSE.
# By accessing, using, copying or modifying this work you indicate your
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.
import os
import sgtk
from sgtk import Hook
from sgtk import TankError
__author__ = "Diego Garcia Huerta"
__contact__ = "https://www.linkedin.com/in/diegogh/"
HookClass = sgtk.get_hook_baseclass()
import sd
class SceneOperation(HookClass):
"""
Hook called to perform an operation with the
current scene
"""
def execute(self, operation, file_path, **kwargs):
"""
Main hook entry point
:operation: String
Scene operation to perform
:file_path: String
File path to use if the operation
requires it (e.g. open)
:returns: Depends on operation:
'current_path' - Return the current scene
file path as a String
all others - None
"""
logger = self.parent.logger
logger.debug("operation: %s" % operation)
logger.debug("file_path: %s" % file_path)
app = self.parent
ctx = sd.getContext()
app = ctx.getSDApplication()
pm = app.getPackageMgr()
uiMgr = app.getQtForPythonUIMgr()
if operation == "current_path":
current_package_filename = ""
current_graph = uiMgr.getCurrentGraph()
if current_graph:
pck = current_graph.getPackage()
current_package_filename = pck.getFilePath()
return current_package_filename
elif operation == "open":
pm.loadUserPackage(file_path, updatePackages=True)
elif operation == "save":
current_graph = uiMgr.getCurrentGraph()
if current_graph:
pck = current_graph.getPackage()
if pck:
# for some reason savePackage did not work
# so we use saveas with the same current filename
pm.savePackageAs(pck, pck.getFilePath())