Adding Files To Created Assets#
This example plugin creates an additional folder in the asset folder, when an asset gets created and copies files into it.
See the section for Single File Plugins on how to load this example.
# AddAssetFiles.py
name = "AddAssetFiles"
classname = "AddAssetFiles"
import os
import shutil
from qtpy.QtWidgets import *
class AddAssetFiles:
def __init__(self, core):
self.core = core
self.version = "v1.0.0"
# register onAssetCreated callback
self.core.registerCallback("onAssetCreated", self.onAssetCreated, plugin=self)
def onAssetCreated(self, origin, entity, dlg):
# get folderpath from created asset
asset_path = self.core.getEntityPath(entity=entity)
# create reference folder
target = os.path.join(asset_path, "References")
if not os.path.exists(target):
os.makedirs(target)
# copy files into reference folder
sourcefiles = [
"D:/library/reference.jpg",
"D:/library/reference2.jpg"
]
for sourcefile in sourcefiles:
shutil.copy2(sourcefile, target)