[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26135] trunk/blender/release/scripts/op/ uv.py: bugfix [#20726] "Export UV Layout" creates invalid SVG files
Campbell Barton
ideasman42 at gmail.com
Wed Jan 20 12:08:50 CET 2010
Revision: 26135
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26135
Author: campbellbarton
Date: 2010-01-20 12:08:50 +0100 (Wed, 20 Jan 2010)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/blender/release/scripts/op/uv.py
Modified: trunk/blender/release/scripts/op/uv.py
===================================================================
--- trunk/blender/release/scripts/op/uv.py 2010-01-20 09:57:47 UTC (rev 26134)
+++ trunk/blender/release/scripts/op/uv.py 2010-01-20 11:08:50 UTC (rev 26135)
@@ -52,6 +52,10 @@
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 @@
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 @@
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):
More information about the Bf-blender-cvs
mailing list