Skip to content

Commit bc3317c

Browse files
authored
move houdini shot open post script to a callback (#266)
1 parent 749bb68 commit bc3317c

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

pipeline/pipe/h/hipfile/filemanager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def _check_unsaved_changes() -> bool:
4040
return False
4141
return True
4242

43-
@staticmethod
44-
def _open_file(path: Path) -> None:
43+
def _open_file(self, path: Path) -> None:
4544
hou.hipFile.load(str(path), suppress_save_prompt=True)
4645

4746
def _setup_file(self, path: Path, entity: SGEntity) -> None:

pipeline/pipe/h/hipfile/shot.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
from typing import cast
88

99
import pipe.h
10+
from pipe.db import DB
1011
from pipe.glui.dialogs import FilteredListDialog
1112
from pipe.struct.db import SGEntity, Shot
1213

14+
from env_sg import DB_Config
15+
1316
from .filemanager import HFileManager
1417

1518

@@ -55,6 +58,26 @@ def _post_open_file(self, entity: SGEntity):
5558
shot = cast(Shot, entity)
5659
hou.playbar.setFrameRange(shot.cut_in - 5, shot.cut_out + 5)
5760
hou.playbar.setPlaybackRange(shot.cut_in - 5, shot.cut_out + 5)
61+
hou.setFrame(shot.cut_in)
62+
63+
def _open_file(self, path):
64+
def do_post_open_file(event: hou.hipFileEventType) -> None:
65+
if event != hou.hipFileEventType.AfterLoad:
66+
return
67+
try:
68+
shot_code = str(hou.contextOption("SHOT")).split("/").pop()
69+
conn = DB.Get(DB_Config)
70+
shot = conn.get_shot_by_code(shot_code)
71+
self._post_open_file(shot)
72+
except Exception:
73+
print("Failed to update frame range!")
74+
75+
hou.hipFile.removeEventCallback(do_post_open_file)
76+
77+
# hou.hipFile.load interrupts the running of the script so we have to
78+
# call _post_open_file with a callback instead
79+
hou.hipFile.addEventCallback(do_post_open_file)
80+
super()._open_file(path)
5881

5982
def _setup_file(self, path: Path, entity: SGEntity) -> None:
6083
super(HShotFileManager, HShotFileManager)._setup_file(self, path, entity)

pipeline/pipe/m/shotfile/shotfile_manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ def _generate_filename_ext(self, entity) -> tuple[str, str]:
118118
shot = cast(Shot, entity)
119119
return shot.code, "mb"
120120

121-
@staticmethod
122-
def _open_file(path: Path) -> None:
121+
def _open_file(self, path: Path) -> None:
123122
mc.file(str(path), open=True, force=True)
124123

125124
def _post_open_file(self, entity: SGEntity) -> None:

pipeline/pipe/util/filemanager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ def _generate_filename_ext(self, entity: SGEntity) -> tuple[str, str]:
9292
def _get_subpath(self) -> str:
9393
return ""
9494

95-
@staticmethod
9695
@abstractmethod
97-
def _open_file(path: Path) -> None:
96+
def _open_file(self, path: Path) -> None:
9897
"""Opens the file into the current session"""
9998
pass
10099

0 commit comments

Comments
 (0)