Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2018-07-05 11:09:37 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2018-07-05 11:09:37 +0300
commit2a0d3baf6fd97bd997afd4df3b5c3fba0b56129a (patch)
tree92f675fed38fd20649a41f6e71f97a6bc7f2a20f /io_curve_svg
parentcdbcfdb98fa59503912606c5e5288aa5e4be177d (diff)
SVG: Port to 2.8
Diffstat (limited to 'io_curve_svg')
-rw-r--r--io_curve_svg/__init__.py2
-rw-r--r--io_curve_svg/import_svg.py33
2 files changed, 21 insertions, 14 deletions
diff --git a/io_curve_svg/__init__.py b/io_curve_svg/__init__.py
index d97b9b43..8ba318c9 100644
--- a/io_curve_svg/__init__.py
+++ b/io_curve_svg/__init__.py
@@ -21,7 +21,7 @@
bl_info = {
"name": "Scalable Vector Graphics (SVG) 1.1 format",
"author": "JM Soler, Sergey Sharybin",
- "blender": (2, 57, 0),
+ "blender": (2, 80, 0),
"location": "File > Import > Scalable Vector Graphics (.svg)",
"description": "Import SVG as curves",
"warning": "",
diff --git a/io_curve_svg/import_svg.py b/io_curve_svg/import_svg.py
index 0dfc70a4..8cd3465c 100644
--- a/io_curve_svg/import_svg.py
+++ b/io_curve_svg/import_svg.py
@@ -118,14 +118,15 @@ def SVGParseFloat(s, i=0):
return token, i
-def SVGCreateCurve():
+def SVGCreateCurve(context):
"""
Create new curve object to hold splines in
"""
cu = bpy.data.curves.new("Curve", 'CURVE')
obj = bpy.data.objects.new("Curve", cu)
- bpy.context.scene.objects.link(obj)
+
+ context['collection'].objects.link(obj)
return obj
@@ -304,7 +305,6 @@ def SVGGetMaterial(color, context):
mat = bpy.data.materials.new(name='SVGMat')
mat.diffuse_color = diffuse_color
- mat.diffuse_intensity = 1.0
materials[color] = mat
@@ -1211,7 +1211,7 @@ class SVGGeometryPATH(SVGGeometry):
Create real geometries
"""
- ob = SVGCreateCurve()
+ ob = SVGCreateCurve(self._context)
cu = ob.data
if self._node.getAttribute('id'):
@@ -1429,7 +1429,7 @@ class SVGGeometryRECT(SVGGeometry):
radius = (rx, ry)
# Geometry creation
- ob = SVGCreateCurve()
+ ob = SVGCreateCurve(self._context)
cu = ob.data
if self._styles['useFill']:
@@ -1539,7 +1539,7 @@ class SVGGeometryELLIPSE(SVGGeometry):
return
# Create circle
- ob = SVGCreateCurve()
+ ob = SVGCreateCurve(self._context)
cu = ob.data
if self._node.getAttribute('id'):
@@ -1656,7 +1656,7 @@ class SVGGeometryLINE(SVGGeometry):
y2 = SVGParseCoord(self._y2, crect[1])
# Create cline
- ob = SVGCreateCurve()
+ ob = SVGCreateCurve(self._context)
cu = ob.data
coords = [(x1, y1), (x2, y2)]
@@ -1727,7 +1727,7 @@ class SVGGeometryPOLY(SVGGeometry):
Create real geometries
"""
- ob = SVGCreateCurve()
+ ob = SVGCreateCurve(self._context)
cu = ob.data
if self._closed and self._styles['useFill']:
@@ -1824,10 +1824,16 @@ class SVGLoader(SVGGeometryContainer):
return None
- def __init__(self, filepath, do_colormanage):
+ def __init__(self, context, filepath, do_colormanage):
"""
Initialize SVG loader
"""
+ import os
+
+ svg_name = os.path.basename(filepath)
+ scene = context.scene
+ collection = bpy.data.collections.new(name=svg_name)
+ scene.collection.children.link(collection)
node = xml.dom.minidom.parse(filepath)
@@ -1845,7 +1851,8 @@ class SVGLoader(SVGGeometryContainer):
'materials': {},
'styles': [None],
'style': None,
- 'do_colormanage': do_colormanage}
+ 'do_colormanage': do_colormanage,
+ 'collection': collection}
super().__init__(node, self._context)
@@ -1882,7 +1889,7 @@ def parseAbstractNode(node, context):
return None
-def load_svg(filepath, do_colormanage):
+def load_svg(context, filepath, do_colormanage):
"""
Load specified SVG file
"""
@@ -1890,7 +1897,7 @@ def load_svg(filepath, do_colormanage):
if bpy.ops.object.mode_set.poll():
bpy.ops.object.mode_set(mode='OBJECT')
- loader = SVGLoader(filepath, do_colormanage)
+ loader = SVGLoader(context, filepath, do_colormanage)
loader.parse()
loader.createGeom(False)
@@ -1901,7 +1908,7 @@ def load(operator, context, filepath=""):
# non SVG files can give useful messages.
do_colormanage = context.scene.display_settings.display_device != 'NONE'
try:
- load_svg(filepath, do_colormanage)
+ load_svg(context, filepath, do_colormanage)
except (xml.parsers.expat.ExpatError, UnicodeEncodeError) as e:
import traceback
traceback.print_exc()