diff --git a/cadquery/CQ.py b/cadquery/CQ.py index e4b870f..8b5f420 100644 --- a/cadquery/CQ.py +++ b/cadquery/CQ.py @@ -637,6 +637,14 @@ class CQ(object): """ exporters.exportSVG(self,fileName) + def importStep(self,fileName): + """ + Reads and imports a solid(s) from a STEP file + + :param fileName: The location and name of the STEP file to load + """ + importers.importStep(self, fileName) + def rotateAboutCenter(self,axisEndPoint,angleDegrees): """ Rotates all items on the stack by the specified angle, about the specified axis diff --git a/cadquery/freecad_impl/importers.py b/cadquery/freecad_impl/importers.py index 4cb7b7c..44c6c32 100644 --- a/cadquery/freecad_impl/importers.py +++ b/cadquery/freecad_impl/importers.py @@ -41,7 +41,7 @@ def importShape(importType,fileName): #Check to see what type of file we're working with if importType == ImportTypes.STEP: - importStep(fileName) + return importStep(fileName) #Loads a STEP file into a CQ object def importStep(fileName): @@ -51,16 +51,12 @@ def importStep(fileName): """ #Now read and return the shape - # try: - rshape = Part.read(fileName) + try: + rshape = Part.read(fileName) - r = Shape.cast(rshape) - #print "loadStep: " + str(r) - #print "Faces=%d" % cadquery.CQ(r).solids().size() - return cadquery.CQ(r) - # except: - # raise ValueError("STEP File Could not be loaded") - -if __name__ == '__main__': - import unittest - unittest.main() + r = Shape.cast(rshape) + #print "loadStep: " + str(r) + #print "Faces=%d" % cadquery.CQ(r).solids().size() + return cadquery.CQ(r) + except: + raise ValueError("STEP File Could not be loaded") diff --git a/tests/TestImporters.py b/tests/TestImporters.py index 6ede15f..52c3cd0 100644 --- a/tests/TestImporters.py +++ b/tests/TestImporters.py @@ -35,6 +35,9 @@ class TestImporters(BaseTest): # Reimport the shape from the new STEP file importedShape = importers.importShape(importType,fileName) + #Check to make sure we got a shape back + if not importedShape.ShapeType: + raise TypeError("Wrong type imported from STEP file.") def testSTEP(self): """ Tests STEP file import