I'm developing blender exporter for CryEngine - CryBlend.
I need to convert an image to tiff and then pass it to cryengine resource compiled. The thing is it works while saving image with blender python console:
tiffImage= bpy.data.images[1].copy()
tiffImage.filepath_raw = 'new_path.tif'
tiffImage.file_format = 'TIFF'
tiffImage.save()
but the same code placed in plugin throws an exception at save()
"RuntimeError: Error: Image "my image" does not have any image data."
What's more, while debugging that code with pydev (in plugin) then it works as expected. I'm totally puzzled with it.
here is the complete code. export.py:1196
def __export_library_images(self, parent_element):
library_images = self.__doc.createElement("library_images")
parent_element.appendChild(library_images)
for image in self.__get_texture_images_for_selected_objects():
tiffFilePath = self.__convert_to_tiff_and_save(image)
image_path = get_relative_path(tiffFilePath)
image_element = self.__doc.createElement("image")
image_element.setAttribute("id", "%s" % image.name)
image_element.setAttribute("name", "%s" % image.name)
init_from = self.__doc.createElement("init_from")
path_node = self.__doc.createTextNode("%s" % image_path)
init_from.appendChild(path_node)
image_element.appendChild(init_from)
library_images.appendChild(image_element)
def __convert_to_tiff_and_save(self, image):
if image.file_format is not 'TIFF':
tiffFilePath = os.path.splitext(image.filepath)[0] + ".tif"
cbPrint(tiffFilePath, 'debug')
if self.__config.run_rc_and_do_materials:
try:
tiffImage = image.copy()
tiffImage.filepath_raw = tiffFilePath
tiffImage.file_format = 'TIFF'
tiffImage.save()
finally:
# remove tmp image from blend file database
bpy.data.images.remove(tiffImage)
else:
tiffFilePath = image.filepath
return tiffFilePath
try
block when this happens, and you're catching all exceptions (bad boy, you!). Also (unrelated), you should never useif image.file_format is not 'TIFF':
This needs to beif image.file_format != TIFF':
. Furthermore, your__convert_to_tiff_etc.()
doesn't return anything, but your other method seems to think it does... $\endgroup$