Skip to content

Commit

Permalink
Started roughing in STEP and STL exporter changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwright committed May 3, 2020
1 parent 23418b9 commit 2aad4ad
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cadquery/cq.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,21 @@ def exportSvg(self, fileName):
"""
exporters.exportSVG(self, fileName)

def exportSTL(self, filename, precision=1e-5):
"""
Exports all solids on the stack to an STL file.
:param filename: The absolute path to the file and the filename, including the extension.
:type filename: String
"""
exporters.exportSTL(self, filename, precision)

def exportSTEP(self, filename):
"""
Exports all the solids on the stack to a STEP file.
"""
exporters.exportSTEP(self, filename)

def rotateAboutCenter(self, axisEndPoint, angleDegrees):
"""
Rotates all items on the stack by the specified angle, about the specified axis
Expand Down
22 changes: 22 additions & 0 deletions cadquery/occ_impl/exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from OCP.HLRBRep import HLRBRep_Algo, HLRBRep_HLRToShape
from OCP.HLRAlgo import HLRAlgo_Projector
from OCP.GCPnts import GCPnts_QuasiUniformDeflection
from OCP.STEPControl import STEPControl_Controller, STEPControl_Writer, STEPControl_AsIs
from OCP.Interface_Static import Interface_Static_SetCVal, Interface_Static_SetIVal

try:
import xml.etree.cElementTree as ET
Expand Down Expand Up @@ -107,6 +109,26 @@ def tessellate(shape):
res = readAndDeleteFile(outFileName)
fileLike.write(res)

def exportSTL(cq_object, filename, precision):
pass

def exportSTEP(self, fileName):
"""
surface_curve_mode:
0: write without pcurves (2 times smaller STEP file)
1 (Default): write with pcurves
"""

obj = Compound._makeCompound([o.vals()[0].wrapped for o in self.all()])
c = STEPControl_Controller()
c.Init()
Interface_Static_SetCVal("write.step.schema", "AP214")
Interface_Static_SetIVal('write.surfacecurve.mode', 0)
writer = STEPControl_Writer()
writer.Transfer(obj.wrapped, STEPControl_AsIs)

return writer.Write(fileName)


def readAndDeleteFile(fileName):
"""
Expand Down
14 changes: 14 additions & 0 deletions tests/test_exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
# core modules
import sys
import io
import tempfile

# my modules
import cadquery as cq
from cadquery import *
from cadquery import exporters
from tests import BaseTest


class TestExporters(BaseTest):
temp_dir = tempfile.gettempdir()

def _exportBox(self, eType, stringsToFind):
"""
Exports a test object, and then looks for
Expand Down Expand Up @@ -49,3 +53,13 @@ def testTJS(self):
self._exportBox(
exporters.ExportTypes.TJS, ["vertices", "formatVersion", "faces"]
)

def testSingleSolidExportSTL(self):
result = cq.Workplane("XY").box(1, 1, 1)
result.exportSTL(self.temp_dir + "/cube_export_1.stl")

def testExportSTEP(self):
result = cq.Workplane("XY").box(1, 1, 1)
result.exportSTEP(self.temp_dir + "/cube_export_1.step")

assert(False)

0 comments on commit 2aad4ad

Please sign in to comment.