I'm trying to export a page View to DXF...
following this
https://www.freecadweb.org/tracker/view.php?id=2882
I tried to use the API as following:
Code: Select all
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# test script for TechDraw module
# creates a page and 2 views
# adds 1 length dimension to view1
# adds 1 radius dimension to view2
from __future__ import print_function
import FreeCAD
import Part
import Measure
import TechDraw
import os
def DVDimensionTest():
path = os.path.dirname(os.path.abspath(__file__))
print ('TDDim path: ' + path)
templateFileSpec = path + '/A4_LandscapeTD.svg'
FreeCAD.newDocument("TDDim")
FreeCAD.setActiveDocument("TDDim")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TDDim")
#make source feature
box = FreeCAD.ActiveDocument.addObject("Part::Box","Box")
sphere = FreeCAD.ActiveDocument.addObject("Part::Sphere","Sphere")
#make a page
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
page.Scale = 5.0
# page.ViewObject.show() # unit tests run in console mode
#make Views
view1 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View')
FreeCAD.ActiveDocument.View.Source = [FreeCAD.ActiveDocument.Box]
rc = page.addView(view1)
FreeCAD.ActiveDocument.recompute()
rc = True
fileSpecDxf = "C:/Temp/fcOut.dxf"
v = App.ActiveDocument.View
#v = view1
s = TechDraw.viewPartAsDxf(v)
dxfEnd = "0\nEOF\n"
dxfFile = open(fileSpecDxf, "w")
dxfFile.write(s)
dxfFile.write(dxfEnd)
dxfFile.close()
return rc
if __name__ == '__main__':
DVDimensionTest()
I'm attaching the dxf out file and my FC details
Thx for supportOS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13387 (Git)
Build type: Release
Branch: master
Hash: c5f4079252b11e3c54cd603be7d3697fa9f9d922
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.1.0
Locale: English/UnitedStates (en_US)
Maurice
PS if I do the same using the svg option, it works
Code: Select all
fileSpecSvg = "c:/Temp/fcOut.svg"
v = App.ActiveDocument.View
s = TechDraw.viewPartAsSvg(v)
head = '<svg\n' + \
' xmlns="http://www.w3.org/2000/svg" version="1.1" \n' + \
' xmlns:freecad="http://www.freecadweb.org/wiki/index.php?title=Svg_Namespace">\n'
tail = '\n</svg>'
svgFile = open(fileSpecSvg, "w")
svgFile.write(head)
svgFile.write(s)
svgFile.write(tail)
svgFile.close()