Asset Pipeline v2 #145
@ -26,9 +26,8 @@ class ASSETPIPE_OT_create_new_asset(bpy.types.Operator):
|
||||
bl_label = "Create New Asset"
|
||||
bl_description = """Create a new Asset Files and Folders at a given directory"""
|
||||
|
||||
_name = None
|
||||
_dir = None
|
||||
_prefix = None
|
||||
_name = ""
|
||||
_prefix = ""
|
||||
_json_path = None
|
||||
|
||||
create_files: bpy.props.BoolProperty(
|
||||
@ -38,16 +37,14 @@ class ASSETPIPE_OT_create_new_asset(bpy.types.Operator):
|
||||
@classmethod
|
||||
def poll(cls, context: bpy.types.Context) -> bool:
|
||||
asset_pipe = context.scene.asset_pipeline
|
||||
if asset_pipe.name == "" or asset_pipe.dir == "":
|
||||
cls.poll_message_set("Asset Name and Directory must be valid")
|
||||
return False
|
||||
if os.path.exists(os.path.join(asset_pipe.dir, asset_pipe.name)):
|
||||
cls.poll_message_set("Asset Folder already exists")
|
||||
return False
|
||||
if bpy.data.filepath == "":
|
||||
cls.poll_message_set("Please Save File before creating asset")
|
||||
return False
|
||||
# TODO Add warning if file is unsaved like a general startup file
|
||||
if asset_pipe.new_file_mode == "KEEP":
|
||||
if not asset_pipe.asset_collection:
|
||||
cls.poll_message_set("Missing Top Level Collection")
|
||||
return False
|
||||
else:
|
||||
if asset_pipe.name == "" or asset_pipe.dir == "":
|
||||
cls.poll_message_set("Asset Name and Directory must be valid")
|
||||
return False
|
||||
return True
|
||||
|
||||
def invoke(self, context: bpy.types.Context, event):
|
||||
@ -77,11 +74,24 @@ class ASSETPIPE_OT_create_new_asset(bpy.types.Operator):
|
||||
self.layout.prop(self, "create_files")
|
||||
|
||||
def execute(self, context: bpy.types.Context):
|
||||
# New File is Createed so Props need to be saved
|
||||
asset_pipe = context.scene.asset_pipeline
|
||||
self._name = asset_pipe.name
|
||||
self._dir = bpy.path.abspath(asset_pipe.dir)
|
||||
self._prefix = asset_pipe.prefix
|
||||
if asset_pipe.new_file_mode == "KEEP":
|
||||
# New File is Createed so Props need to be saved
|
||||
asset_col = asset_pipe.asset_collection
|
||||
self._name == "FOO"
|
||||
self._name = (
|
||||
asset_col.name
|
||||
if "-" not in asset_col.name
|
||||
else asset_col.name.split("-", 1)[1]
|
||||
)
|
||||
asset_path = Path(bpy.data.filepath).parent.__str__()
|
||||
|
||||
else:
|
||||
self._name = asset_pipe.name
|
||||
user_dir = bpy.path.abspath(asset_pipe.dir)
|
||||
self._prefix = asset_pipe.prefix
|
||||
# Create Asset Folder at Directory
|
||||
asset_path = os.path.join(user_dir, self._name)
|
||||
|
||||
all_task_layers = context.scene.asset_pipeline.all_task_layers
|
||||
local_tls = []
|
||||
@ -96,12 +106,18 @@ class ASSETPIPE_OT_create_new_asset(bpy.types.Operator):
|
||||
)
|
||||
return {'CANCELLED'}
|
||||
|
||||
# Create Asset Folder at Directory
|
||||
asset_path = os.path.join(self._dir, self._name)
|
||||
os.mkdir(asset_path)
|
||||
if not os.path.exists(asset_path):
|
||||
os.mkdir(asset_path)
|
||||
|
||||
for publish_type in constants.PUBLISH_KEYS:
|
||||
os.mkdir(os.path.join(asset_path, publish_type))
|
||||
new_dir_path = os.path.join(asset_path, publish_type)
|
||||
if os.path.exists(new_dir_path):
|
||||
self.report(
|
||||
{'ERROR'},
|
||||
f"Directory for '{publish_type}' already exists",
|
||||
)
|
||||
return {'CANCELLED'}
|
||||
os.mkdir(new_dir_path)
|
||||
|
||||
# TODO Save Task Layer Config File
|
||||
config.write_json_file(
|
||||
@ -112,10 +128,17 @@ class ASSETPIPE_OT_create_new_asset(bpy.types.Operator):
|
||||
# Setup Base File
|
||||
asset_pipe = context.scene.asset_pipeline
|
||||
asset_pipe.is_asset_pipeline_file = True
|
||||
bpy.data.collections.new(self._name)
|
||||
asset_col = bpy.data.collections.get(self._name)
|
||||
context.scene.collection.children.link(asset_col)
|
||||
asset_pipe.asset_collection = asset_col
|
||||
|
||||
if asset_pipe.new_file_mode == "KEEP":
|
||||
asset_col = asset_pipe.asset_collection
|
||||
for col in asset_col.children:
|
||||
col.asset_id_owner = local_tls[0]
|
||||
else:
|
||||
bpy.data.collections.new(self._name)
|
||||
asset_col = bpy.data.collections.get(self._name)
|
||||
context.scene.collection.children.link(asset_col)
|
||||
asset_pipe.asset_collection = asset_col
|
||||
|
||||
asset_pipe.name = self._name
|
||||
asset_pipe.prefix = self._prefix
|
||||
|
||||
@ -126,7 +149,11 @@ class ASSETPIPE_OT_create_new_asset(bpy.types.Operator):
|
||||
asset_col.children.link(task_layer_col)
|
||||
|
||||
starting_file = ""
|
||||
first_file = os.path.join(asset_path, Path(bpy.data.filepath).name)
|
||||
if bpy.data.filepath != "":
|
||||
first_file_name = Path(bpy.data.filepath).name
|
||||
else:
|
||||
first_file_name = self._name + "." + local_tls[0].lower() + ".blend"
|
||||
first_file = os.path.join(asset_path, first_file_name)
|
||||
|
||||
set_local_task_layers(local_tls)
|
||||
|
||||
@ -156,7 +183,6 @@ class ASSETPIPE_OT_create_new_asset(bpy.types.Operator):
|
||||
bpy.ops.wm.save_as_mainfile(filepath=task_layer_file, copy=True)
|
||||
|
||||
# Create intial publish based on task layers.
|
||||
asset_pipe.task_layer_name = "NONE"
|
||||
publish_path = os.path.join(asset_path, constants.ACTIVE_PUBLISH_KEY)
|
||||
name = self._name + "." + "v001" + ".blend"
|
||||
asset_pipe.asset_collection.asset_mark()
|
||||
|
@ -86,6 +86,14 @@ class AssetPipeline(bpy.types.PropertyGroup):
|
||||
|
||||
## NEW FILE
|
||||
|
||||
new_file_mode: bpy.props.EnumProperty(
|
||||
name="New File Mode",
|
||||
items=(
|
||||
('KEEP', "Current File", "Update Selected Objects Only"),
|
||||
('BLANK', "Blank", "Update All Objects"),
|
||||
),
|
||||
)
|
||||
|
||||
dir: bpy.props.StringProperty(
|
||||
name="Directory",
|
||||
description="Target Path for new asset files",
|
||||
|
@ -18,12 +18,15 @@ class ASSETPIPE_PT_sync(bpy.types.Panel):
|
||||
layout = self.layout
|
||||
asset_pipe = context.scene.asset_pipeline
|
||||
if not asset_pipe.is_asset_pipeline_file:
|
||||
layout.prop(asset_pipe, "dir")
|
||||
layout.prop(asset_pipe, "name")
|
||||
layout.prop(asset_pipe, "prefix")
|
||||
layout.prop(asset_pipe, "new_file_mode", expand=True)
|
||||
layout.prop(asset_pipe, "task_layer_config_type")
|
||||
if asset_pipe.new_file_mode == "BLANK":
|
||||
layout.prop(asset_pipe, "name")
|
||||
layout.prop(asset_pipe, "prefix")
|
||||
layout.prop(asset_pipe, "dir")
|
||||
else:
|
||||
layout.prop(asset_pipe, "asset_collection")
|
||||
layout.operator("assetpipe.create_new_asset")
|
||||
# layout.operator("")
|
||||
return
|
||||
|
||||
if not Path(bpy.data.filepath).exists:
|
||||
|
Loading…
Reference in New Issue
Block a user