diff options
Diffstat (limited to 'object_print3d_utils/export.py')
-rw-r--r-- | object_print3d_utils/export.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/object_print3d_utils/export.py b/object_print3d_utils/export.py index 3a2b6677..4c582f8a 100644 --- a/object_print3d_utils/export.py +++ b/object_print3d_utils/export.py @@ -24,6 +24,31 @@ import bpy import os +def image_copy_guess(filepath, objects): + # 'filepath' is the path we are writing to. + import shutil + from bpy_extras import object_utils + image = None + for obj in objects: + image = object_utils.object_image_guess(obj) + if image is not None: + break + + if image is not None: + imagepath = bpy.path.abspath(image.filepath, library=image.library) + if os.path.exists(imagepath): + filepath_noext = os.path.splitext(filepath)[0] + ext = os.path.splitext(imagepath)[1] + + imagepath_dst = filepath_noext + ext + print("copying texture: %r -> %r" % (imagepath, imagepath_dst)) + try: + shutil.copy(imagepath, imagepath_dst) + except: + import traceback + traceback.print_exc() + + def write_mesh(context, info, report_cb): scene = context.scene print_3d = scene.print_3d @@ -32,6 +57,7 @@ def write_mesh(context, info, report_cb): obj = obj_base.object export_format = print_3d.export_format + path_mode = 'COPY' if print_3d.use_export_texture else 'AUTO' context_override = context.copy() @@ -111,6 +137,7 @@ def write_mesh(context, info, report_cb): filepath=filepath, use_mesh_modifiers=True, use_selection=True, + path_mode=path_mode, ) elif export_format == 'WRL': addon_ensure("io_scene_vrml2") @@ -120,6 +147,7 @@ def write_mesh(context, info, report_cb): filepath=filepath, use_mesh_modifiers=True, use_selection=True, + path_mode=path_mode, ) elif export_format == 'OBJ': addon_ensure("io_scene_obj") @@ -129,10 +157,16 @@ def write_mesh(context, info, report_cb): filepath=filepath, use_mesh_modifiers=True, use_selection=True, + path_mode=path_mode, ) else: assert(0) + # for formats that don't support images + if export_format in {'STL', 'PLY'}: + if path_mode == 'COPY': + image_copy_guess(filepath, context_override["selected_objects"]) + if obj_base_tmp is not None: obj = obj_base_tmp.object mesh = obj.data |