Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
exposed view_vector as kwarg for SVG export
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-james-v committed Jan 26, 2018
1 parent 97521c5 commit a6106bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cadquery/cq.py
Expand Up @@ -682,7 +682,7 @@ def toSvg(self, opts=None):
"""
return exporters.getSVG(self.val().wrapped, opts)

def exportSvg(self, fileName):
def exportSvg(self, fileName, view_vector=(-1.75,1.1,5)):
"""
Exports the first item on the stack as an SVG file
Expand All @@ -691,7 +691,7 @@ def exportSvg(self, fileName):
:param fileName: the filename to export
:type fileName: String, absolute path to the file
"""
exporters.exportSVG(self, fileName)
exporters.exportSVG(self, fileName, view_vector)

def rotateAboutCenter(self, axisEndPoint, angleDegrees):
"""
Expand Down
9 changes: 4 additions & 5 deletions cadquery/freecad_impl/exporters.py
Expand Up @@ -236,7 +236,7 @@ def getPaths(freeCadSVG):
return ([],[])


def getSVG(shape,opts=None):
def getSVG(shape, view_vector, opts=None):
"""
Export a shape to SVG
"""
Expand All @@ -255,7 +255,7 @@ def getSVG(shape,opts=None):
marginTop=float(d['marginTop'])

#TODO: provide option to give 3 views
viewVector = FreeCAD.Base.Vector(-1.75,1.1,5)
viewVector = FreeCAD.Base.Vector(view_vector)
(visibleG0,visibleG1,hiddenG0,hiddenG1) = Drawing.project(shape,viewVector)

(hiddenPaths,visiblePaths) = getPaths(Drawing.projectToSVG(shape,viewVector,"ShowHiddenLines")) #this param is totally undocumented!
Expand Down Expand Up @@ -301,14 +301,13 @@ def getSVG(shape,opts=None):
return svg


def exportSVG(shape, fileName):
def exportSVG(shape, fileName, view_vector=(-1.75,1.1,5)):
"""
accept a cadquery shape, and export it to the provided file
TODO: should use file-like objects, not a fileName, and/or be able to return a string instead
export a view of a part to svg
"""

svg = getSVG(shape.val().wrapped)
svg = getSVG(shape.val().wrapped, view_vector)
f = open(fileName,'w')
f.write(svg)
f.close()
Expand Down

0 comments on commit a6106bf

Please sign in to comment.