Skip to content

Commit

Permalink
create new blend file
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxuanzhuang committed Oct 15, 2024
1 parent d3ec888 commit e28cd4b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion ggmolvis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""

import os
import shutil
import tempfile
from importlib.metadata import version
import bpy
from bpy.app.handlers import frame_change_post
Expand All @@ -25,7 +27,23 @@
os.path.abspath(mn.utils.ADDON_DIR),
"assets", "template", "startup.blend"
)
bpy.ops.wm.open_mainfile(filepath=mn_template_file)
base_name = 'ggmolvis.blend'
name, ext = os.path.splitext(base_name)
dest_path = os.path.join('.', base_name)
dest_dir = '.'
if not os.access(dest_dir, os.W_OK):
print(f"Directory {dest_dir} is not writable. Using a temporary directory.")
dest_dir = tempfile.gettempdir()

count = 1
while os.path.exists(dest_path):
dest_path = os.path.join(dest_dir, f"{name}_{count}{ext}")
count += 1

shutil.copy(mn_template_file, dest_path)


bpy.ops.wm.open_mainfile(filepath=dest_path)


@persistent
Expand Down

0 comments on commit e28cd4b

Please sign in to comment.