mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
moved nuke implementation from avalon
This commit is contained in:
parent
7d13728371
commit
e4368e69b1
47 changed files with 1581 additions and 563 deletions
55
openpype/hosts/nuke/api/workio.py
Normal file
55
openpype/hosts/nuke/api/workio.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
"""Host API required Work Files tool"""
|
||||
import os
|
||||
import nuke
|
||||
import avalon.api
|
||||
|
||||
|
||||
def file_extensions():
|
||||
return avalon.api.HOST_WORKFILE_EXTENSIONS["nuke"]
|
||||
|
||||
|
||||
def has_unsaved_changes():
|
||||
return nuke.root().modified()
|
||||
|
||||
|
||||
def save_file(filepath):
|
||||
path = filepath.replace("\\", "/")
|
||||
nuke.scriptSaveAs(path)
|
||||
nuke.Root()["name"].setValue(path)
|
||||
nuke.Root()["project_directory"].setValue(os.path.dirname(path))
|
||||
nuke.Root().setModified(False)
|
||||
|
||||
|
||||
def open_file(filepath):
|
||||
filepath = filepath.replace("\\", "/")
|
||||
|
||||
# To remain in the same window, we have to clear the script and read
|
||||
# in the contents of the workfile.
|
||||
nuke.scriptClear()
|
||||
nuke.scriptReadFile(filepath)
|
||||
nuke.Root()["name"].setValue(filepath)
|
||||
nuke.Root()["project_directory"].setValue(os.path.dirname(filepath))
|
||||
nuke.Root().setModified(False)
|
||||
return True
|
||||
|
||||
|
||||
def current_file():
|
||||
current_file = nuke.root().name()
|
||||
|
||||
# Unsaved current file
|
||||
if current_file == 'Root':
|
||||
return None
|
||||
|
||||
return os.path.normpath(current_file).replace("\\", "/")
|
||||
|
||||
|
||||
def work_root(session):
|
||||
|
||||
work_dir = session["AVALON_WORKDIR"]
|
||||
scene_dir = session.get("AVALON_SCENEDIR")
|
||||
if scene_dir:
|
||||
path = os.path.join(work_dir, scene_dir)
|
||||
else:
|
||||
path = work_dir
|
||||
|
||||
return os.path.normpath(path).replace("\\", "/")
|
||||
Loading…
Add table
Add a link
Reference in a new issue