From e7dd10ac56ffa6c79c83a60bb407ab6a65905e58 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 11 Mar 2024 20:45:24 +0100 Subject: [PATCH 01/10] Improve icon for model creator --- client/ayon_core/hosts/zbrush/plugins/create/create_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/hosts/zbrush/plugins/create/create_model.py b/client/ayon_core/hosts/zbrush/plugins/create/create_model.py index 8e132aed18..47e2a09f2a 100644 --- a/client/ayon_core/hosts/zbrush/plugins/create/create_model.py +++ b/client/ayon_core/hosts/zbrush/plugins/create/create_model.py @@ -9,7 +9,7 @@ class CreateModel(plugin.ZbrushCreator): identifier = "io.ayon.creators.zbrush.model" label = "Model" product_type = "model" - icon = "gear" + icon = "cube" def create(self, product_name, instance_data, pre_create_data): creator_attributes = instance_data.setdefault( From 82f0b9b46cba82ca162e219d41315cd64a6a93c1 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 11 Mar 2024 20:48:25 +0100 Subject: [PATCH 02/10] Fix cosmetics --- client/ayon_core/hosts/zbrush/api/pipeline.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/hosts/zbrush/api/pipeline.py b/client/ayon_core/hosts/zbrush/api/pipeline.py index ba6d2b597d..623377faf6 100644 --- a/client/ayon_core/hosts/zbrush/api/pipeline.py +++ b/client/ayon_core/hosts/zbrush/api/pipeline.py @@ -53,7 +53,6 @@ class ZbrushHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost): register_event_callback("application.launched", self.initial_app_launch) register_event_callback("application.exit", self.application_exit) - def get_current_project_name(self): """ Returns: @@ -90,6 +89,7 @@ class ZbrushHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost): "folder_path": context.get("folder_path"), "task_name": context.get("task") } + # --- Workfile --- def open_workfile(self, filepath): open_file_zscript = (""" @@ -194,6 +194,7 @@ class ZbrushHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost): def get_context_data(self): get_load_workfile_metadata(ZBRUSH_METADATA_CREATE_CONTEXT) + def containerise( name, context, namespace="", loader=None, containers=None): data = { @@ -311,6 +312,7 @@ def get_containers(): return output + def write_load_metadata(metadata_key, data): #TODO: create temp json file project_name = get_current_context()["project_name"] @@ -546,6 +548,7 @@ def imprint(container, representation_id): file.write(new_container_data) file.close() + def tmp_current_file_check(): output_file = tempfile.NamedTemporaryFile( mode="w", prefix="a_zb_cfc", suffix=".txt", delete=False From b3da71b5537787dc0d0111d1d8b94b2291c0b011 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 12 Mar 2024 00:40:53 +0100 Subject: [PATCH 03/10] Simplify save/open zscripts --- client/ayon_core/hosts/zbrush/api/pipeline.py | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/client/ayon_core/hosts/zbrush/api/pipeline.py b/client/ayon_core/hosts/zbrush/api/pipeline.py index 623377faf6..d40cf92f1f 100644 --- a/client/ayon_core/hosts/zbrush/api/pipeline.py +++ b/client/ayon_core/hosts/zbrush/api/pipeline.py @@ -92,17 +92,13 @@ class ZbrushHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost): # --- Workfile --- def open_workfile(self, filepath): - open_file_zscript = (""" + filepath = filepath.replace("\\", "/") + execute_zscript(f""" [IFreeze, -[MemCreate, currentfile, 1000, 0] -[VarSet, filename, "{filepath}"] -[MemWriteString, currentfile, #filename, 0] -[FileNameSetNext, #filename] -[IKeyPress, 13, [IPress, File:Open:Open]]] -[MemDelete, currentfile] + [FileNameSetNext, "{filepath}"] + [IKeyPress, 13, [IPress, File:Open:Open]]] ] - """).format(filepath=filepath) - execute_zscript(open_file_zscript) + """) set_current_file(filepath=filepath) return filepath @@ -110,21 +106,16 @@ class ZbrushHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost): if not filepath: filepath = self.get_current_workfile() filepath = filepath.replace("\\", "/") - save_file_zscript = (""" -[IFreeze, -[MemCreate, currentfile, 1000, 0] -[VarSet, filename, "{filepath}"] -[MemWriteString, currentfile, #filename, 0] -[FileNameSetNext, #filename] -[IKeyPress, 13, [IPress, File:SaveAs:SaveAs]]] -[MemDelete, currentfile] -] -""").format(filepath=filepath) # # move the json data to the files # # shutil.copy copy_ayon_data(filepath) set_current_file(filepath=filepath) - execute_zscript(save_file_zscript) + execute_zscript(f""" +[IFreeze, + [FileNameSetNext, "{filepath}"] + [IKeyPress, 13, [IPress, File:SaveAs:SaveAs]]] +] +""") return filepath def work_root(self, session): From a37c982a38221a301e669368d740517107bbd6a1 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 12 Mar 2024 00:42:07 +0100 Subject: [PATCH 04/10] Remove unused function --- client/ayon_core/hosts/zbrush/api/pipeline.py | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/client/ayon_core/hosts/zbrush/api/pipeline.py b/client/ayon_core/hosts/zbrush/api/pipeline.py index d40cf92f1f..657e623cb8 100644 --- a/client/ayon_core/hosts/zbrush/api/pipeline.py +++ b/client/ayon_core/hosts/zbrush/api/pipeline.py @@ -266,31 +266,6 @@ def get_current_context(): } -def get_workfile_metadata(metadata_key, default=None): - if default is None: - default = [] - output_file = tempfile.NamedTemporaryFile( - mode="w", prefix="a_zb_meta", suffix=".txt", delete=False - ) - output_file.close() - output_filepath = output_file.name.replace("\\", "/") - context_data_zscript = (""" -[IFreeze, -[If, [MemCreate, {metadata_key}, 400000, 0] !=-1, -[MemCreate, {metadata_key}, 400000, 0] -[MemWriteString, {metadata_key}, "{default}", 0]] -[MemSaveToFile, {metadata_key}, "{output_filepath}", 1] -[MemDelete, {metadata_key}] -] -""").format(metadata_key=metadata_key, - default=default, output_filepath=output_filepath) - execute_zscript(context_data_zscript) - with open(output_filepath) as data: - file_content = str(data.read().strip()).rstrip('\x00') - file_content = ast.literal_eval(file_content) - return file_content - - def get_containers(): output = get_load_workfile_metadata(ZBRUSH_SECTION_NAME_CONTAINERS) if output: From 5436cf08d54ff2dd14bd9e6482bd1c5874ecb662 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 12 Mar 2024 02:55:39 +0100 Subject: [PATCH 05/10] Simplify get workdir --- client/ayon_core/hosts/zbrush/api/lib.py | 42 ++----------------- client/ayon_core/hosts/zbrush/api/pipeline.py | 24 +++++------ 2 files changed, 16 insertions(+), 50 deletions(-) diff --git a/client/ayon_core/hosts/zbrush/api/lib.py b/client/ayon_core/hosts/zbrush/api/lib.py index 7b288008e4..5814146b42 100644 --- a/client/ayon_core/hosts/zbrush/api/lib.py +++ b/client/ayon_core/hosts/zbrush/api/lib.py @@ -1,16 +1,11 @@ +import functools import os import uuid import time import tempfile import logging -from ayon_core.client import ( - get_project, - get_asset_by_name, -) -from ayon_core.pipeline import Anatomy -from string import Formatter + from . import CommunicationWrapper -from ayon_core.pipeline.template_data import get_template_data log = logging.getLogger("zbrush.lib") @@ -88,37 +83,8 @@ def execute_zscript_and_wait(zscript, ) -def find_first_filled_path(path): - if not path: - return "" - - fields = set() - for item in Formatter().parse(path): - _, field_name, format_spec, conversion = item - if not field_name: - continue - conversion = "!{}".format(conversion) if conversion else "" - format_spec = ":{}".format(format_spec) if format_spec else "" - orig_key = "{{{}{}{}}}".format( - field_name, conversion, format_spec) - fields.add(orig_key) - - for field in fields: - path = path.split(field, 1)[0] - return path - - -def get_workdir(project_name, asset_name, task_name): - project = get_project(project_name) - asset = get_asset_by_name(project_name, asset_name) - - data = get_template_data(project, asset, task_name) - - anatomy = Anatomy(project_name) - workdir = anatomy.templates_obj["work"]["folder"].format(data) - - # Remove any potential un-formatted parts of the path - valid_workdir = find_first_filled_path(workdir) +def get_workdir(): + return os.environ["AYON_WORKDIR"] # Path is not filled at all if not valid_workdir: diff --git a/client/ayon_core/hosts/zbrush/api/pipeline.py b/client/ayon_core/hosts/zbrush/api/pipeline.py index 657e623cb8..74254db177 100644 --- a/client/ayon_core/hosts/zbrush/api/pipeline.py +++ b/client/ayon_core/hosts/zbrush/api/pipeline.py @@ -125,7 +125,7 @@ class ZbrushHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost): project_name = get_current_context()["project_name"] folder_path = get_current_context()["folder_path"] task_name = get_current_context()["task_name"] - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() txt_dir = os.path.join( work_dir, ".zbrush_metadata").replace( "\\", "/" @@ -213,7 +213,7 @@ def write_context_metadata(metadata_key, context): project_name = get_current_context()["project_name"] folder_path = get_current_context()["folder_path"] task_name = get_current_context()["task_name"] - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", metadata_key).replace( "\\", "/" @@ -241,7 +241,7 @@ def write_workfile_metadata(metadata_key, data=None): if current_file: current_file = os.path.splitext( os.path.basename(current_file))[0].strip() - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", current_file, metadata_key).replace( @@ -288,7 +288,7 @@ def write_load_metadata(metadata_key, data): if current_file: current_file = os.path.splitext( os.path.basename(current_file))[0].strip() - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() name = next((d["name"] for d in data), None) json_dir = os.path.join( work_dir, ".zbrush_metadata", @@ -310,7 +310,7 @@ def get_load_context_metadata(metadata_key): project_name = get_current_context()["project_name"] folder_path = get_current_context()["folder_path"] task_name = get_current_context()["task_name"] - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", metadata_key).replace( "\\", "/" @@ -338,7 +338,7 @@ def get_load_workfile_metadata(metadata_key): if current_file: current_file = os.path.splitext( os.path.basename(current_file))[0].strip() - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", current_file, metadata_key).replace( @@ -368,7 +368,7 @@ def get_instance_workfile_metadata(metadata_key): if current_file: current_file = os.path.splitext( os.path.basename(current_file))[0].strip() - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", current_file, metadata_key).replace( @@ -391,7 +391,7 @@ def remove_container_data(name): if current_file: current_file = os.path.splitext( os.path.basename(current_file))[0].strip() - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", current_file, ZBRUSH_SECTION_NAME_CONTAINERS).replace( @@ -408,7 +408,7 @@ def remove_tmp_data(): project_name = get_current_context()["project_name"] folder_path = get_current_context()["folder_path"] task_name = get_current_context()["task_name"] - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() for name in [ZBRUSH_METADATA_CREATE_CONTEXT, ZBRUSH_SECTION_NAME_INSTANCES, ZBRUSH_SECTION_NAME_CONTAINERS]: @@ -433,7 +433,7 @@ def copy_ayon_data(filepath): if current_file: current_file = os.path.splitext( os.path.basename(current_file))[0].strip() - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() for name in [ZBRUSH_METADATA_CREATE_CONTEXT, ZBRUSH_SECTION_NAME_INSTANCES, ZBRUSH_SECTION_NAME_CONTAINERS]: @@ -461,7 +461,7 @@ def set_current_file(filepath=None): project_name = get_current_context()["project_name"] folder_path = get_current_context()["folder_path"] task_name = get_current_context()["task_name"] - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() txt_dir = os.path.join( work_dir, ".zbrush_metadata").replace( "\\", "/" @@ -491,7 +491,7 @@ def imprint(container, representation_id): if current_file: current_file = os.path.splitext( os.path.basename(current_file))[0].strip() - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", current_file, ZBRUSH_SECTION_NAME_CONTAINERS).replace( From 796dbb80190b3ea0dc602b080d99459e86859433 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 12 Mar 2024 03:03:34 +0100 Subject: [PATCH 06/10] Fix refactor of last commit + remove unused variables/import --- client/ayon_core/hosts/zbrush/api/pipeline.py | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/client/ayon_core/hosts/zbrush/api/pipeline.py b/client/ayon_core/hosts/zbrush/api/pipeline.py index 74254db177..13c0a2edda 100644 --- a/client/ayon_core/hosts/zbrush/api/pipeline.py +++ b/client/ayon_core/hosts/zbrush/api/pipeline.py @@ -122,9 +122,6 @@ class ZbrushHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost): return session["AYON_WORKDIR"] def get_current_workfile(self): - project_name = get_current_context()["project_name"] - folder_path = get_current_context()["folder_path"] - task_name = get_current_context()["task_name"] work_dir = get_workdir() txt_dir = os.path.join( work_dir, ".zbrush_metadata").replace( @@ -210,9 +207,6 @@ def save_current_workfile_context(context): def write_context_metadata(metadata_key, context): - project_name = get_current_context()["project_name"] - folder_path = get_current_context()["folder_path"] - task_name = get_current_context()["task_name"] work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", metadata_key).replace( @@ -234,9 +228,6 @@ def write_context_metadata(metadata_key, context): def write_workfile_metadata(metadata_key, data=None): if data is None: data = [] - project_name = get_current_context()["project_name"] - folder_path = get_current_context()["folder_path"] - task_name = get_current_context()["task_name"] current_file = registered_host().get_current_workfile() if current_file: current_file = os.path.splitext( @@ -281,9 +272,6 @@ def get_containers(): def write_load_metadata(metadata_key, data): #TODO: create temp json file - project_name = get_current_context()["project_name"] - folder_path = get_current_context()["folder_path"] - task_name = get_current_context()["task_name"] current_file = registered_host().get_current_workfile() if current_file: current_file = os.path.splitext( @@ -307,9 +295,6 @@ def write_load_metadata(metadata_key, data): def get_load_context_metadata(metadata_key): file_content = [] - project_name = get_current_context()["project_name"] - folder_path = get_current_context()["folder_path"] - task_name = get_current_context()["task_name"] work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", metadata_key).replace( @@ -331,9 +316,6 @@ def get_load_workfile_metadata(metadata_key): # save zscript to the hidden folder # load json files file_content = [] - project_name = get_current_context()["project_name"] - folder_path = get_current_context()["folder_path"] - task_name = get_current_context()["task_name"] current_file = registered_host().get_current_workfile() if current_file: current_file = os.path.splitext( @@ -361,9 +343,6 @@ def get_instance_workfile_metadata(metadata_key): # save zscript to the hidden folder # load json files file_content = [] - project_name = get_current_context()["project_name"] - folder_path = get_current_context()["folder_path"] - task_name = get_current_context()["task_name"] current_file = registered_host().get_current_workfile() if current_file: current_file = os.path.splitext( @@ -384,9 +363,6 @@ def get_instance_workfile_metadata(metadata_key): def remove_container_data(name): - project_name = get_current_context()["project_name"] - folder_path = get_current_context()["folder_path"] - task_name = get_current_context()["task_name"] current_file = registered_host().get_current_workfile() if current_file: current_file = os.path.splitext( @@ -405,9 +381,6 @@ def remove_container_data(name): def remove_tmp_data(): - project_name = get_current_context()["project_name"] - folder_path = get_current_context()["folder_path"] - task_name = get_current_context()["task_name"] work_dir = get_workdir() for name in [ZBRUSH_METADATA_CREATE_CONTEXT, ZBRUSH_SECTION_NAME_INSTANCES, @@ -426,9 +399,6 @@ def remove_tmp_data(): def copy_ayon_data(filepath): filename = os.path.splitext(os.path.basename(filepath))[0].strip() - project_name = get_current_context()["project_name"] - folder_path = get_current_context()["folder_path"] - task_name = get_current_context()["task_name"] current_file = registered_host().get_current_workfile() if current_file: current_file = os.path.splitext( @@ -458,9 +428,6 @@ def copy_ayon_data(filepath): def set_current_file(filepath=None): - project_name = get_current_context()["project_name"] - folder_path = get_current_context()["folder_path"] - task_name = get_current_context()["task_name"] work_dir = get_workdir() txt_dir = os.path.join( work_dir, ".zbrush_metadata").replace( @@ -484,9 +451,6 @@ def imprint(container, representation_id): old_container_data = [] data = {} name = container["objectName"] - project_name = get_current_context()["project_name"] - folder_path = get_current_context()["folder_path"] - task_name = get_current_context()["task_name"] current_file = registered_host().get_current_workfile() if current_file: current_file = os.path.splitext( From 27053f3f8b4c52fdf8da14fe88d203dc3dc68c3a Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 12 Mar 2024 09:18:21 +0100 Subject: [PATCH 07/10] Fix removal of code (somehow this didn't commit) --- client/ayon_core/hosts/zbrush/api/lib.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/client/ayon_core/hosts/zbrush/api/lib.py b/client/ayon_core/hosts/zbrush/api/lib.py index 5814146b42..a8ed05bb7b 100644 --- a/client/ayon_core/hosts/zbrush/api/lib.py +++ b/client/ayon_core/hosts/zbrush/api/lib.py @@ -1,4 +1,3 @@ -import functools import os import uuid import time @@ -86,24 +85,6 @@ def execute_zscript_and_wait(zscript, def get_workdir(): return os.environ["AYON_WORKDIR"] - # Path is not filled at all - if not valid_workdir: - raise AssertionError("Failed to calculate workdir.") - - # Normalize - valid_workdir = os.path.normpath(valid_workdir) - if os.path.exists(valid_workdir): - return valid_workdir - - data.pop("task", None) - workdir = anatomy.templates_obj["work"]["folder"].format(data) - valid_workdir = find_first_filled_path(workdir) - if valid_workdir: - # Normalize - valid_workdir = os.path.normpath(valid_workdir) - if os.path.exists(valid_workdir): - return valid_workdir - def export_tool(filepath: str, sub_level: int): """Export active zbrush tool to filepath.""" From 9bc0fa9f003f58f554356228fc998635315ff573 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 12 Mar 2024 09:21:02 +0100 Subject: [PATCH 08/10] Fix return type `is_in_edit_mode`, cosmetics + type hints --- client/ayon_core/hosts/zbrush/api/lib.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/ayon_core/hosts/zbrush/api/lib.py b/client/ayon_core/hosts/zbrush/api/lib.py index a8ed05bb7b..b3bb24c458 100644 --- a/client/ayon_core/hosts/zbrush/api/lib.py +++ b/client/ayon_core/hosts/zbrush/api/lib.py @@ -82,7 +82,8 @@ def execute_zscript_and_wait(zscript, ) -def get_workdir(): +def get_workdir() -> str: + """Return the currently active work directory""" return os.environ["AYON_WORKDIR"] @@ -109,7 +110,7 @@ def export_tool(filepath: str, sub_level: int): sub_level=sub_level) -def is_in_edit_mode(): +def is_in_edit_mode() -> bool: """Return whether transform edit mode is currently enabled. Certain actions can't be performed if Zbrush is currently not within @@ -135,7 +136,7 @@ def is_in_edit_mode(): content = str(mode.read()) bool_mode = content.rstrip('\x00') - return bool_mode + return bool(int(bool_mode)) def remove_subtool(basename): From 8931028391c05f948dfd90e41ddafc251da744e8 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 12 Mar 2024 09:23:34 +0100 Subject: [PATCH 09/10] Tweak export tool code --- client/ayon_core/hosts/zbrush/api/lib.py | 43 ++++++++++++------- .../zbrush/plugins/create/create_model.py | 18 +++++--- .../plugins/publish/collect_current_file.py | 4 ++ 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/client/ayon_core/hosts/zbrush/api/lib.py b/client/ayon_core/hosts/zbrush/api/lib.py index b3bb24c458..1020575795 100644 --- a/client/ayon_core/hosts/zbrush/api/lib.py +++ b/client/ayon_core/hosts/zbrush/api/lib.py @@ -40,7 +40,6 @@ def execute_zscript(zscript, communicator=None): def execute_zscript_and_wait(zscript, check_filepath=None, - sub_level=0, wait=0.1, timeout=20): """Execute ZScript and wait until ZScript finished processing. @@ -87,27 +86,41 @@ def get_workdir() -> str: return os.environ["AYON_WORKDIR"] -def export_tool(filepath: str, sub_level: int): - """Export active zbrush tool to filepath.""" +def export_tool(filepath: str, subdivision_level: int = 0): + """Export active zbrush tool to filepath. + + Args: + filepath (str): The filepath to export to. + subdivision_level (int): The subdivision level to export. + A value of zero will export the current subdivision level + A negative value, e.g. -1 will go negatively from the highest + subdivs - e.g. -1 is the highest available subdiv. + + """ filepath = filepath.replace("\\", "/") - export_tool_zscript = (""" -[IFreeze, -[VarSet, subdlevel, {sub_level}] -[VarSet, maxSubd, [IGetMax, Tool:Geometry:SDiv]] -[If, subdlevel == 0 || sublevel > maxSubd, -[VarSet, subdlevel, maxSubd]] -[ISet, "Tool:Geometry:SDiv", subdlevel, 0] + + # Only set any subdiv level if subdiv level != 0 + set_subdivs_script = "" + if subdivision_level != 0: + set_subdivs_script = f""" +[VarSet, max_subd, [IGetMax, "Tool:Geometry:SDiv"]] +[If, max_subd > 0, + [ISet, "Tool:Geometry:SDiv", {subdivision_level}, 0], + [ISet, "Tool:Geometry:SDiv", [VarGet, max_subd] - {subdivision_level}, 0] +]""" + + # Export tool + export_tool_zscript = f""" +[IFreeze, {set_subdivs_script} [FileNameSetNext, "{filepath}"] [IKeyPress, 13, [IPress, Tool:Export]] -] -""").format(filepath=filepath, sub_level=sub_level) + +]""" # We do not check for the export file's existence because Zbrush might # write the file in chunks, as such the file might exist before the writing # to it has finished - execute_zscript_and_wait( - export_tool_zscript, check_filepath=filepath, - sub_level=sub_level) + execute_zscript_and_wait(export_tool_zscript, check_filepath=filepath) def is_in_edit_mode() -> bool: diff --git a/client/ayon_core/hosts/zbrush/plugins/create/create_model.py b/client/ayon_core/hosts/zbrush/plugins/create/create_model.py index 47e2a09f2a..348e519e14 100644 --- a/client/ayon_core/hosts/zbrush/plugins/create/create_model.py +++ b/client/ayon_core/hosts/zbrush/plugins/create/create_model.py @@ -25,11 +25,19 @@ class CreateModel(plugin.ZbrushCreator): def get_instance_attr_defs(self): return [ - NumberDef("subd_level", - label="Subdivision Level", - decimals=0, - minimum=0, - default=0) + NumberDef( + "subd_level", + label="Subdivision Level", + decimals=0, + minimum=-10, + default=0, + tooltip=( + "A level of 1 or higher sets the level to export at.\n" + "A level of 0 means 'Use tool's current subdiv level'.\n" + "A level of -1 or lower subtracts from the highest subdiv," + "\n for example -1 means highest subdiv level." + ) + ) ] def get_pre_create_attr_defs(self): diff --git a/client/ayon_core/hosts/zbrush/plugins/publish/collect_current_file.py b/client/ayon_core/hosts/zbrush/plugins/publish/collect_current_file.py index dd29618539..e3ba009bc3 100644 --- a/client/ayon_core/hosts/zbrush/plugins/publish/collect_current_file.py +++ b/client/ayon_core/hosts/zbrush/plugins/publish/collect_current_file.py @@ -2,6 +2,10 @@ import pyblish.api from ayon_core.pipeline import registered_host +import importlib +import ayon_core.hosts.zbrush.api.lib +importlib.reload(ayon_core.hosts.zbrush.api.lib) + class CollectCurrentFile(pyblish.api.ContextPlugin): label = "Collect Current File" From cbb5ec25c1a2cfee0071f0bd713d51b4bab2ca15 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 12 Mar 2024 09:23:59 +0100 Subject: [PATCH 10/10] Remove temporary debug reload code --- .../hosts/zbrush/plugins/publish/collect_current_file.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/client/ayon_core/hosts/zbrush/plugins/publish/collect_current_file.py b/client/ayon_core/hosts/zbrush/plugins/publish/collect_current_file.py index e3ba009bc3..dd29618539 100644 --- a/client/ayon_core/hosts/zbrush/plugins/publish/collect_current_file.py +++ b/client/ayon_core/hosts/zbrush/plugins/publish/collect_current_file.py @@ -2,10 +2,6 @@ import pyblish.api from ayon_core.pipeline import registered_host -import importlib -import ayon_core.hosts.zbrush.api.lib -importlib.reload(ayon_core.hosts.zbrush.api.lib) - class CollectCurrentFile(pyblish.api.ContextPlugin): label = "Collect Current File"