Asset Pipeline v2 #145
@ -4,17 +4,73 @@ from . import core
|
||||
from pathlib import Path
|
||||
from . import constants
|
||||
from .transfer_data import transfer_ui
|
||||
import os
|
||||
|
||||
# TODO Add operator to create new Asset
|
||||
# # User Input Directory where Folder is
|
||||
# # User Input Name of Asset
|
||||
# # Create Asset Parent Folder at Directory
|
||||
# # Create Directories for Piublish/Staged/Review
|
||||
# # Create a file per task Layer
|
||||
# # Create Asset Col
|
||||
# # Set Asset Col Pointer
|
||||
# # Set is Asset Pipe File Prop
|
||||
# # Creata intial publish based on task layers
|
||||
|
||||
class ASSETPIPE_OT_create_new_asset(bpy.types.Operator):
|
||||
bl_idname = "assetpipe.create_new_asset"
|
||||
bl_label = "Create New Asset"
|
||||
bl_description = """Create a new Asset""" # TODO Improve description
|
||||
|
||||
_name = None
|
||||
_dir = None
|
||||
|
||||
# TODO add poll method to check if name and directory are valid before running
|
||||
|
||||
def execute(self, context: bpy.types.Context):
|
||||
# New File is Createed so Props need to be saved
|
||||
new_asset = context.scene.asset_new
|
||||
self._name = new_asset.name
|
||||
self._dir = new_asset.dir
|
||||
|
||||
# Create Asset Folder at Directory
|
||||
asset_path = os.path.join(self._dir, self._name)
|
||||
os.mkdir(asset_path)
|
||||
|
||||
for publish_type in constants.PUBLISH_KEYS:
|
||||
os.mkdir(os.path.join(asset_path, publish_type))
|
||||
|
||||
# Prepare New File
|
||||
bpy.ops.wm.read_homefile(app_template="")
|
||||
|
||||
# Remove All Data
|
||||
for col in bpy.data.collections:
|
||||
bpy.data.collections.remove(col)
|
||||
for obj in bpy.data.objects:
|
||||
bpy.data.objects.remove(obj)
|
||||
|
||||
bpy.ops.outliner.orphans_purge(
|
||||
do_local_ids=True, do_linked_ids=False, do_recursive=True
|
||||
)
|
||||
|
||||
# Setup New File
|
||||
asset_status = context.scene.asset_status
|
||||
asset_status.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_status.asset_collection = asset_col
|
||||
|
||||
for task_layer_name in constants.TASK_LAYER_NAMES:
|
||||
if task_layer_name == "None":
|
||||
continue
|
||||
bpy.data.collections.new(task_layer_name)
|
||||
asset_col.children.link(bpy.data.collections.get(task_layer_name))
|
||||
|
||||
for task_layer_key in reversed(constants.TASK_LAYER_KEYS):
|
||||
if task_layer_key == "NONE":
|
||||
continue
|
||||
name = self._name + "." + task_layer_key + ".blend"
|
||||
task_layer_file = os.path.join(asset_path, name)
|
||||
bpy.ops.wm.save_as_mainfile(filepath=task_layer_file, copy=True)
|
||||
|
||||
# Creata intial publish based on task layers
|
||||
publish_path = os.path.join(asset_path, "publish") # TODO FIX HARD CODE VALUE
|
||||
name = self._name + "." + "v001" + ".blend"
|
||||
publish_file = os.path.join(publish_path, name)
|
||||
bpy.ops.wm.save_as_mainfile(filepath=publish_file, copy=True)
|
||||
bpy.ops.wm.open_mainfile(filepath=task_layer_file)
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class ASSETPIPE_OT_sync_with_publish(bpy.types.Operator):
|
||||
@ -184,7 +240,11 @@ class ASSETPIPE_OT_publish_new_version(bpy.types.Operator):
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
classes = (ASSETPIPE_OT_sync_with_publish, ASSETPIPE_OT_publish_new_version)
|
||||
classes = (
|
||||
ASSETPIPE_OT_sync_with_publish,
|
||||
ASSETPIPE_OT_publish_new_version,
|
||||
ASSETPIPE_OT_create_new_asset,
|
||||
)
|
||||
|
||||
|
||||
def register():
|
||||
|
@ -14,7 +14,10 @@ class ASSETPIPE_sync(bpy.types.Panel):
|
||||
layout = self.layout
|
||||
status = context.scene.asset_status
|
||||
if not status.is_asset_pipeline_file:
|
||||
layout.label(text="Isn't Asset Pipeline File")
|
||||
new_asset = context.scene.asset_new
|
||||
layout.prop(new_asset, "dir")
|
||||
layout.prop(new_asset, "name")
|
||||
layout.operator("assetpipe.create_new_asset")
|
||||
# layout.operator("")
|
||||
return
|
||||
layout.label(
|
||||
|
Loading…
Reference in New Issue
Block a user