diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-01-20 14:08:50 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-01-20 14:08:50 +0300 |
commit | 09424badda213ea71aaded574b8004bae6fae4f6 (patch) | |
tree | aa0be13e5242a3ab96d40ff31d4ec69a396b20e8 | |
parent | 22ca6f69cafb054a0260409b72ec7fadc411e115 (diff) |
bugfix [#20726] "Export UV Layout" creates invalid SVG files
- use xml.sax.saxutils.escape() to give an XML compatible string.
- in some cases material indicies could be invalid. use the default material rather then throwing an error.
-rw-r--r-- | release/scripts/op/uv.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/release/scripts/op/uv.py b/release/scripts/op/uv.py index 1ca369abe64..619c1e6f502 100644 --- a/release/scripts/op/uv.py +++ b/release/scripts/op/uv.py @@ -52,6 +52,10 @@ class ExportUVLayout(bpy.types.Operator): return image_width, image_height def execute(self, context): + # for making an XML compatible string + from xml.sax.saxutils import escape + from os.path import basename + ob = context.active_object is_editmode = (ob.mode == 'EDIT') if is_editmode: @@ -84,15 +88,17 @@ class ExportUVLayout(bpy.types.Operator): fw('<svg width="%dpx" height="%dpx" viewBox="0px 0px %dpx %dpx"\n' % (image_width, image_height, image_width, image_height)) fw(' xmlns="http://www.w3.org/2000/svg" version="1.1">\n') - fw('<desc>%s, %s, %s (Blender %s)</desc>\n' % (bpy.data.filename, ob.name, mesh.name, bpy.app.version_string)) - + desc = "%s, %s, %s (Blender %s)" % (basename(bpy.data.filename), ob.name, mesh.name, bpy.app.version_string) + fw('<desc>%s</desc>\n' % escape(desc)) + # svg colors fill_settings = [] + fill_default = 'fill="grey"' for mat in mesh.materials if mesh.materials else [None]: if mat: fill_settings.append('fill="rgb(%d, %d, %d)"' % tuple(int(c*255) for c in mat.diffuse_color)) else: - fill_settings.append('fill="grey"') + fill_settings.append(fill_default) only_selected = self.properties.only_selected @@ -105,8 +111,13 @@ class ExportUVLayout(bpy.types.Operator): uvs = uv.uv1, uv.uv2, uv.uv3 else: uvs = uv.uv1, uv.uv2, uv.uv3, uv.uv4 + + try: # rare cases material index is invalid. + fill = fill_settings[faces[i].material_index] + except IndexError: + fill = fill_default - fw('<polygon %s fill-opacity="0.5" stroke="black" stroke-width="1px" \n' % fill_settings[faces[i].material_index]) + fw('<polygon %s fill-opacity="0.5" stroke="black" stroke-width="1px" \n' % fill) fw(' points="') for j, uv in enumerate(uvs): |