Skip to content

Commit

Permalink
Support both 4.2 and older versions
Browse files Browse the repository at this point in the history
  • Loading branch information
kwsxing committed Oct 28, 2024
1 parent 26f1db9 commit 6d6b40d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions imagepaste/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
import bpy


# override the api
def bpy_ops_import_image_to_plane(*args, **kwargs):
if bpy.app.version[0] < 4 or (bpy.app.version[0] == 4 and bpy.app.version[1] < 2):
return bpy.ops.import_image.to_plane(*args, **kwargs)
# the latest api
return bpy.ops.image.import_as_mesh_planes(*args, **kwargs)

def bpy_ops_object_load_reference_image(*args, **kwargs):
if bpy.app.version[0] < 4 or (bpy.app.version[0] == 4 and bpy.app.version[1] < 2):
return bpy.ops.object.load_reference_image(*args, **kwargs)
# the latest api
return bpy.ops.object.empty_image_add(*args, **kwargs)


class IMAGEPASTE_OT_imageeditor_copy(bpy.types.Operator):
"""Copy image to the clipboard"""

Expand Down Expand Up @@ -158,7 +172,7 @@ def execute(self, _context):
if clipboard.report.type != "INFO":
return {"CANCELLED"}
for image in clipboard.images:
bpy.ops.import_image.to_plane(files=[{"name": image.filepath}])
bpy_ops_import_image_to_plane(files=[{"name": image.filepath}])
return {"FINISHED"}

@classmethod
Expand All @@ -185,7 +199,7 @@ def execute(self, _context):
if clipboard.report.type != "INFO":
return {"CANCELLED"}
for image in clipboard.images:
bpy.ops.object.load_reference_image(filepath=image.filepath)
bpy_ops_object_load_reference_image(filepath=image.filepath)
return {"FINISHED"}

@classmethod
Expand Down

0 comments on commit 6d6b40d

Please sign in to comment.