custom_shelf/devshelf/Tool/rendu/create_lighting_file.py

59 lines
1.4 KiB
Python

info = {
'icon' : 'LIGHT_SPOT',
'description' : 'Save as lighting file from currently opened anim file',
}
import bpy
import os
from os import listdir
from os.path import join, dirname, basename, exists, isfile, isdir, splitext
import re, fnmatch, glob
from mathutils import Vector, Matrix
from math import radians, degrees
import datetime
C = bpy.context
D = bpy.data
scene = C.scene
def create_lighting_file():
'''Create lighting_v001 file from anim'''
# if D.is_dirty:
# print('Current file is not saved')
# return
if 'lighting' in D.filepath:
print('File already detected as lighting')
return
if not 'animation' in D.filepath:
print('Not in animation folder')
return
name = re.sub(r'anim_v\d{3}', 'lighting_v001', basename(D.filepath))
print('name: ', name)
fp = dirname(dirname(D.filepath))
print('shot path: ', fp)
fp = join(fp, 'lighting', name)
print('light filepath: ', fp)
if exists(fp):
print('lighting_v001 already exists in folder')
return
info = D.texts.get('info')
if not info:
info = D.texts.new('info')
info.write(f'\nCreated from {basename(D.filepath)} at {str( datetime.datetime.now() )}')
print('Saving current file as lighting')
bpy.ops.wm.save_as_mainfile(filepath=fp)
print('Done')
create_lighting_file()