I am having a weird problem with my script. The first try, I noticed that a StrngProperty was not registering, but I was not getting an error when the script was using it in my Panel class and Operator class. I then purposely forced the script to cause an error by misspelling an UILayout property, and I did not get an error with that either. So then, I realized that it must be that the script was not running at all. I tried restarting Blender, and weirdness still exists. Below is my script and I have highlighted the line in bold where Blender should be complaining about the misspelling of the UILayout property.
import bpy
def GetImageFormat(self) :
if "image_format_prop" in self :
return self["image_format_prop"]
else :
return -1
def UpdateImageFormat(self, value) :
self["image_format_prop"] = value
bpy.context.scene.image_format = value
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "scene.save_images"
bl_label = "Multiple image save Operator"
@classmethod
def poll(cls, context):
return True #bpy.data.textures is not None #context.active_object is not None
def execute(self, context):
scene = context.scene
path = scene.custom_path
image_foramt = scene.image_format
rd = scene.render
tex = bpy.data.textures.values().copy() #[t.image.name for t in bpy.data.textures.values()]
print(tex)
#save
name = tex[0].image.name
bpy.ops.image_save_as(filepath=path+name+image_format)
return {'FINISHED'}
class ExportMultipleImages(bpy.types.Panel):
"""Creates a Panel in the image editor, allowing to set the path to save and save all images by chosen image file format"""
bl_label = "Multiple image saver"
bl_idname = "IMAGE_EDITOR_PT_layout"
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'TOOLS'
bl_context = "image"
def draw(self, context):
layout = self.layout
scene = context.scene
rd = scene.render
col = layout.column()
col.label("Output Path:")
<b>col.protp(rd, "filepath", text_ctxt=scene.custom_path, text="path") <-- this should be considered as an erorr</b>
col.prop(scene, "image_format_prop") #, "1")
op = col.operator("scene.save_images", text="Save All As", icon="TEXTURE")
print(scene.custom_path)
def register():
bpy.utils.register_class(ExportMultipleImages)
bpy.utils.register_class(SimpleOperator)
bpy.types.Scene.image_format_prop = bpy.props.EnumProperty(items = (("1", "bmp", "Bitmap"), ("2", "png", "PNG"), ("3", "jpg", "JPG"), ("4", "tga", "Targa")), name="File Format", description="List of file formats", get=GetImageFormat, set=UpdateImageFormat)
bpy.types.Scene.custom_path = bpy.props.StringProperty(name="custom_path", default="file") #bpy.path.abspath("//../"))
bpy.types.Scene.image_format = bpy.props.StringProperty(name="")
def unregister():
bpy.utils.unregister_class(ExportMultipleImages)
bpy.utils.unregister_class(SimpleOperator)
if __name__ == "__main__":
register()