@@ -2075,6 +2075,8 @@ def getEllipse(edge):
2075
2075
2076
2076
def getArrow (arrowtype ,point ,arrowsize ,color ,linewidth ,angle = 0 ):
2077
2077
svg = ""
2078
+ if not obj .ViewObject :
2079
+ return svg
2078
2080
if obj .ViewObject .ArrowType == "Circle" :
2079
2081
svg += '<circle cx="' + str (point .x )+ '" cy="' + str (point .y )
2080
2082
svg += '" r="' + str (arrowsize )+ '" '
@@ -2189,7 +2191,9 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
2189
2191
2190
2192
2191
2193
elif getType (obj ) == "Dimension" :
2192
- if obj .ViewObject .Proxy :
2194
+ if not obj .ViewObject :
2195
+ print ("export of dimensions to SVG is only available in GUI mode" )
2196
+ elif obj .ViewObject .Proxy :
2193
2197
if hasattr (obj .ViewObject .Proxy ,"p1" ):
2194
2198
prx = obj .ViewObject .Proxy
2195
2199
ts = (len (prx .string )* obj .ViewObject .FontSize .Value )/ 4.0
@@ -2259,7 +2263,9 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
2259
2263
svg += getText (stroke ,fontsize ,obj .ViewObject .FontName ,tangle ,tbase ,prx .string )
2260
2264
2261
2265
elif getType (obj ) == "AngularDimension" :
2262
- if obj .ViewObject .Proxy :
2266
+ if not obj .ViewObject :
2267
+ print ("export of dimensions to SVG is only available in GUI mode" )
2268
+ elif obj .ViewObject .Proxy :
2263
2269
if hasattr (obj .ViewObject .Proxy ,"circle" ):
2264
2270
prx = obj .ViewObject .Proxy
2265
2271
@@ -2309,52 +2315,58 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
2309
2315
2310
2316
elif getType (obj ) == "Annotation" :
2311
2317
"returns an svg representation of a document annotation"
2312
- n = obj .ViewObject .FontName
2313
- a = obj .ViewObject .Rotation .getValueAs ("rad" )
2314
- t = obj .LabelText
2315
- j = obj .ViewObject .Justification
2316
- svg += getText (stroke ,fontsize ,n ,a ,getProj (obj .Position ),t ,linespacing ,j )
2318
+ if not obj .ViewObject :
2319
+ print ("export of texts to SVG is only available in GUI mode" )
2320
+ else :
2321
+ n = obj .ViewObject .FontName
2322
+ a = obj .ViewObject .Rotation .getValueAs ("rad" )
2323
+ t = obj .LabelText
2324
+ j = obj .ViewObject .Justification
2325
+ svg += getText (stroke ,fontsize ,n ,a ,getProj (obj .Position ),t ,linespacing ,j )
2317
2326
2318
2327
elif getType (obj ) == "Axis" :
2319
2328
"returns the SVG representation of an Arch Axis system"
2320
- vobj = obj .ViewObject
2321
- lorig = getLineStyle ()
2322
- fill = 'none'
2323
- rad = vobj .BubbleSize .Value / 2
2324
- n = 0
2325
- for e in obj .Shape .Edges :
2326
- lstyle = lorig
2327
- svg += getPath ([e ])
2328
- lstyle = "none"
2329
- pos = ["Start" ]
2330
- if hasattr (vobj ,"BubblePosition" ):
2331
- if vobj .BubblePosition == "Both" :
2332
- pos = ["Start" ,"End" ]
2333
- else :
2334
- pos = [vobj .BubblePosition ]
2335
- for p in pos :
2336
- if p == "Start" :
2337
- p1 = e .Vertexes [0 ].Point
2338
- p2 = e .Vertexes [1 ].Point
2339
- else :
2340
- p1 = e .Vertexes [1 ].Point
2341
- p2 = e .Vertexes [0 ].Point
2342
- dv = p2 .sub (p1 )
2343
- dv .normalize ()
2344
- center = p2 .add (dv .scale (rad ,rad ,rad ))
2345
- svg += getCircle (Part .makeCircle (rad ,center ))
2346
- if hasattr (vobj .Proxy ,"bubbletexts" ):
2347
- if len (vobj .Proxy .bubbletexts ) >= n :
2348
- svg += '<text fill="' + stroke + '" '
2349
- svg += 'font-size="' + str (rad ) + '" '
2350
- svg += 'style="text-anchor:middle;'
2351
- svg += 'text-align:center;'
2352
- svg += 'font-family: sans;" '
2353
- svg += 'transform="translate(' + str (center .x + rad / 4.0 ) + ',' + str (center .y - rad / 3.0 ) + ') '
2354
- svg += 'scale(1,-1)"> '
2355
- svg += '<tspan>' + obj .ViewObject .Proxy .bubbletexts [n ].string .getValues ()[0 ] + '</tspan>\n '
2356
- svg += '</text>\n '
2357
- n += 1
2329
+ if not obj .ViewObject :
2330
+ print ("export of axes to SVG is only available in GUI mode" )
2331
+ else :
2332
+ vobj = obj .ViewObject
2333
+ lorig = getLineStyle ()
2334
+ fill = 'none'
2335
+ rad = vobj .BubbleSize .Value / 2
2336
+ n = 0
2337
+ for e in obj .Shape .Edges :
2338
+ lstyle = lorig
2339
+ svg += getPath ([e ])
2340
+ lstyle = "none"
2341
+ pos = ["Start" ]
2342
+ if hasattr (vobj ,"BubblePosition" ):
2343
+ if vobj .BubblePosition == "Both" :
2344
+ pos = ["Start" ,"End" ]
2345
+ else :
2346
+ pos = [vobj .BubblePosition ]
2347
+ for p in pos :
2348
+ if p == "Start" :
2349
+ p1 = e .Vertexes [0 ].Point
2350
+ p2 = e .Vertexes [1 ].Point
2351
+ else :
2352
+ p1 = e .Vertexes [1 ].Point
2353
+ p2 = e .Vertexes [0 ].Point
2354
+ dv = p2 .sub (p1 )
2355
+ dv .normalize ()
2356
+ center = p2 .add (dv .scale (rad ,rad ,rad ))
2357
+ svg += getCircle (Part .makeCircle (rad ,center ))
2358
+ if hasattr (vobj .Proxy ,"bubbletexts" ):
2359
+ if len (vobj .Proxy .bubbletexts ) >= n :
2360
+ svg += '<text fill="' + stroke + '" '
2361
+ svg += 'font-size="' + str (rad ) + '" '
2362
+ svg += 'style="text-anchor:middle;'
2363
+ svg += 'text-align:center;'
2364
+ svg += 'font-family: sans;" '
2365
+ svg += 'transform="translate(' + str (center .x + rad / 4.0 ) + ',' + str (center .y - rad / 3.0 ) + ') '
2366
+ svg += 'scale(1,-1)"> '
2367
+ svg += '<tspan>' + obj .ViewObject .Proxy .bubbletexts [n ].string .getValues ()[0 ] + '</tspan>\n '
2368
+ svg += '</text>\n '
2369
+ n += 1
2358
2370
2359
2371
elif getType (obj ) == "Pipe" :
2360
2372
fill = stroke
@@ -2371,25 +2383,28 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
2371
2383
2372
2384
elif getType (obj ) == "Space" :
2373
2385
"returns an SVG fragment for the text of a space"
2374
- c = getrgb (obj .ViewObject .TextColor )
2375
- n = obj .ViewObject .FontName
2376
- a = 0
2377
- if rotation != 0 :
2378
- a = math .radians (rotation )
2379
- t1 = obj .ViewObject .Proxy .text1 .string .getValues ()
2380
- t2 = obj .ViewObject .Proxy .text2 .string .getValues ()
2381
- scale = obj .ViewObject .FirstLine .Value / obj .ViewObject .FontSize .Value
2382
- f1 = fontsize * scale
2383
- p2 = FreeCAD .Vector (obj .ViewObject .Proxy .coords .translation .getValue ().getValue ())
2384
- lspc = FreeCAD .Vector (obj .ViewObject .Proxy .header .translation .getValue ().getValue ())
2385
- p1 = p2 .add (lspc )
2386
- j = obj .ViewObject .TextAlign
2387
- svg += getText (c ,f1 ,n ,a ,getProj (p1 ),t1 ,linespacing ,j ,flip = True )
2388
- if t2 :
2389
- ofs = FreeCAD .Vector (0 ,lspc .Length ,0 )
2390
- if a :
2391
- ofs = FreeCAD .Rotation (FreeCAD .Vector (0 ,0 ,1 ),- rotation ).multVec (ofs )
2392
- svg += getText (c ,fontsize ,n ,a ,getProj (p1 ).add (ofs ),t2 ,linespacing ,j ,flip = True )
2386
+ if not obj .ViewObject :
2387
+ print ("export of spaces to SVG is only available in GUI mode" )
2388
+ else :
2389
+ c = getrgb (obj .ViewObject .TextColor )
2390
+ n = obj .ViewObject .FontName
2391
+ a = 0
2392
+ if rotation != 0 :
2393
+ a = math .radians (rotation )
2394
+ t1 = obj .ViewObject .Proxy .text1 .string .getValues ()
2395
+ t2 = obj .ViewObject .Proxy .text2 .string .getValues ()
2396
+ scale = obj .ViewObject .FirstLine .Value / obj .ViewObject .FontSize .Value
2397
+ f1 = fontsize * scale
2398
+ p2 = FreeCAD .Vector (obj .ViewObject .Proxy .coords .translation .getValue ().getValue ())
2399
+ lspc = FreeCAD .Vector (obj .ViewObject .Proxy .header .translation .getValue ().getValue ())
2400
+ p1 = p2 .add (lspc )
2401
+ j = obj .ViewObject .TextAlign
2402
+ svg += getText (c ,f1 ,n ,a ,getProj (p1 ),t1 ,linespacing ,j ,flip = True )
2403
+ if t2 :
2404
+ ofs = FreeCAD .Vector (0 ,lspc .Length ,0 )
2405
+ if a :
2406
+ ofs = FreeCAD .Rotation (FreeCAD .Vector (0 ,0 ,1 ),- rotation ).multVec (ofs )
2407
+ svg += getText (c ,fontsize ,n ,a ,getProj (p1 ).add (ofs ),t2 ,linespacing ,j ,flip = True )
2393
2408
2394
2409
elif obj .isDerivedFrom ('Part::Feature' ):
2395
2410
if obj .Shape .isNull ():
0 commit comments