diff --git a/src/Mod/Draft/draftfunctions/svg.py b/src/Mod/Draft/draftfunctions/svg.py
index 2b30ccb55b..c2137cf1a3 100644
--- a/src/Mod/Draft/draftfunctions/svg.py
+++ b/src/Mod/Draft/draftfunctions/svg.py
@@ -103,8 +103,9 @@ def get_arrow(obj,
arrowtype, point, arrowsize, color, linewidth, angle=0):
"""Get the SVG representation from an arrow."""
svg = ""
+ vobj = _get_view_object(obj)
- if not App.GuiUp or not obj.ViewObject:
+ if not App.GuiUp or vobj is None:
return svg
_cx_cy_r = 'cx="{}" cy="{}" r="{}"'.format(point.x, point.y, arrowsize)
@@ -114,7 +115,7 @@ def get_arrow(obj,
_scale = 'scale({size},{size})'.format(size=arrowsize)
_style = 'style="stroke-miterlimit:4;stroke-dasharray:none;stroke-linecap:square"'
- if obj.ViewObject.ArrowType == "Circle":
+ if vobj.ArrowType == "Circle":
svg += '\n'
- elif obj.ViewObject.ArrowType == "Dot":
+ elif vobj.ArrowType == "Dot":
svg += '\n'
- elif obj.ViewObject.ArrowType == "Arrow":
+ elif vobj.ArrowType == "Arrow":
svg += '\n'
- elif obj.ViewObject.ArrowType == "Tick":
+ elif vobj.ArrowType == "Tick":
svg += '\n'
- elif obj.ViewObject.ArrowType == "Tick-2":
+ elif vobj.ArrowType == "Tick-2":
svg += '= 2:
+ if hasattr(vobj, "ArrowType") and len(obj.Points) >= 2:
last_segment = App.Vector(obj.Points[-1] - obj.Points[-2])
_v = get_proj(last_segment, plane)
angle = -DraftVecUtils.angle(_v) + math.pi
svg += get_arrow(obj,
- obj.ViewObject.ArrowType,
+ vobj.ArrowType,
proj_points[-1],
- obj.ViewObject.ArrowSize.Value/pointratio,
+ vobj.ArrowSize.Value/pointratio,
stroke, linewidth, angle)
if not App.GuiUp:
@@ -640,10 +680,10 @@ def get_svg(obj,
# print text
if App.GuiUp:
- fontname = obj.ViewObject.FontName
+ fontname = vobj.FontName
position = get_proj(obj.Placement.Base, plane)
rotation = obj.Placement.Rotation
- justification = obj.ViewObject.Justification
+ justification = vobj.Justification
text = obj.Text
svg += svgtext.get_text(plane, techdraw,
tstroke, fontsize, fontname,
@@ -656,17 +696,17 @@ def get_svg(obj,
_wrn("Export of texts to SVG is only available in GUI mode")
if App.GuiUp:
- n = obj.ViewObject.FontName
+ n = vobj.FontName
if utils.get_type(obj) == "Annotation":
p = get_proj(obj.Position, plane)
- r = obj.ViewObject.Rotation.getValueAs("rad")
+ r = vobj.Rotation.getValueAs("rad")
t = obj.LabelText
else: # DraftText (old) or Text (new, 0.19)
p = get_proj(obj.Placement.Base, plane)
r = obj.Placement.Rotation
t = obj.Text
- j = obj.ViewObject.Justification
+ j = vobj.Justification
svg += svgtext.get_text(plane, techdraw,
tstroke, fontsize, n,
r, p, t,
@@ -678,8 +718,7 @@ def get_svg(obj,
_wrn("Export of axes to SVG is only available in GUI mode")
if App.GuiUp:
- vobj = obj.ViewObject
- fn = obj.ViewObject.FontName
+ fn = vobj.FontName
fill = 'none'
rad = vobj.BubbleSize.Value/2
n = 0
@@ -688,13 +727,13 @@ def get_svg(obj,
fill, pathdata, stroke, linewidth, lstyle,
fill_opacity=None,
edges=[e])
- for t in obj.ViewObject.Proxy.getTextData():
+ for t in vobj.Proxy.getTextData():
pos = t[1].add(App.Vector(0,-fontsize/2,0))
svg += svgtext.get_text(plane, techdraw,
tstroke, fontsize, fn,
0.0, pos, t[0],
1.0, "center")
- for b in obj.ViewObject.Proxy.getShapeData():
+ for b in vobj.Proxy.getShapeData():
if hasattr(b,"Curve") and isinstance(b.Curve,Part.Circle):
svg += get_circle(plane,
fill, stroke, linewidth, "none",
@@ -749,7 +788,6 @@ def get_svg(obj,
_wrn("Export of spaces to SVG is only available in GUI mode")
if App.GuiUp:
- vobj = obj.ViewObject
if fillspaces and hasattr(obj, "Proxy"):
if not hasattr(obj.Proxy, "face"):
obj.Proxy.getArea(obj, notouch=True)
@@ -818,11 +856,10 @@ def get_svg(obj,
if obj.Shape.Faces:
if App.GuiUp:
try:
- m = obj.ViewObject.DisplayMode
+ m = vobj.DisplayMode
except AttributeError:
m = None
- vobj = obj.ViewObject
if m != "Wireframe":
if (fillstyle == "shape color") and hasattr(vobj,"ShapeColor"):
fill = utils.get_rgb(vobj.ShapeColor,
@@ -884,17 +921,17 @@ def get_svg(obj,
edges=obj.Shape.Edges)
if (App.GuiUp
- and hasattr(obj.ViewObject, "EndArrow")
- and obj.ViewObject.EndArrow
- and hasattr(obj.ViewObject, "ArrowType")
+ and hasattr(vobj, "EndArrow")
+ and vobj.EndArrow
+ and hasattr(vobj, "ArrowType")
and len(obj.Shape.Vertexes) > 1):
p1 = get_proj(obj.Shape.Vertexes[-1].Point, plane)
p2 = get_proj(obj.Shape.Vertexes[-2].Point, plane)
angle = -DraftVecUtils.angle(p2 - p1)
- arrowsize = obj.ViewObject.ArrowSize.Value/pointratio
+ arrowsize = vobj.ArrowSize.Value/pointratio
svg += get_arrow(obj,
- obj.ViewObject.ArrowType,
+ vobj.ArrowType,
p1, arrowsize, stroke, linewidth, angle)
# techdraw expects bottom-to-top coordinates
@@ -904,6 +941,18 @@ def get_svg(obj,
return svg
+def _get_view_object(obj):
+ if obj.isDerivedFrom("App::Link") \
+ and hasattr(obj, "ViewObject") \
+ and hasattr(obj.ViewObject, "OverrideMaterial") \
+ and not obj.ViewObject.OverrideMaterial \
+ and hasattr(obj.LinkedObject, "ViewObject"):
+ return obj.LinkedObject.ViewObject
+ if hasattr(obj, "ViewObject"):
+ return obj.ViewObject
+ return None
+
+
# Similar function as in view_layer.py
def _get_layer(obj):
"""Get the layer the object belongs to."""