From e51b54d6c4f284b5d0351fabf03d535d0ccf8be7 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Thu, 11 Dec 2014 14:35:29 -0500 Subject: [PATCH] Made the STEP import function more robust so that it could return a CQ.Workplane object. --- cadquery/CQ.py | 4 +-- cadquery/freecad_impl/geom.py | 3 -- cadquery/freecad_impl/importers.py | 48 ++++++++++++++++-------------- cadquery/freecad_impl/shapes.py | 4 --- 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/cadquery/CQ.py b/cadquery/CQ.py index ec0b583..d2a5d8e 100644 --- a/cadquery/CQ.py +++ b/cadquery/CQ.py @@ -679,8 +679,8 @@ class CQ(object): startPt = obj.Center() endPt = startPt + endVec obj.rotate(startPt,endPt,angleDegrees) - - return self.each(_rot,False) + + return self.each(_rot, False) def translate(self,vec): """ diff --git a/cadquery/freecad_impl/geom.py b/cadquery/freecad_impl/geom.py index 1818693..df2daf2 100644 --- a/cadquery/freecad_impl/geom.py +++ b/cadquery/freecad_impl/geom.py @@ -18,9 +18,6 @@ """ import math,sys -#import FreeCAD -#from .verutil import fc_import -#FreeCAD = fc_import("FreeCAD") import FreeCAD #Turns out we don't need the Part module here. diff --git a/cadquery/freecad_impl/importers.py b/cadquery/freecad_impl/importers.py index c959fb9..9a4243e 100644 --- a/cadquery/freecad_impl/importers.py +++ b/cadquery/freecad_impl/importers.py @@ -20,10 +20,8 @@ a string containing the model content. """ import cadquery -from .shapes import Shape -#from .verutil import fc_import -# FreeCAD = fc_import("FreeCAD") -# Part = fc_import("FreeCAD.Part") +from .shapes import Shape, Compound + import FreeCAD import Part @@ -34,31 +32,35 @@ class UNITS: MM = "mm" IN = "in" -def importShape(importType,fileName): - """ - Imports a file based on the type (STEP, STL, etc) - :param importType: The type of file that we're importing - :param fileName: THe name of the file that we're importing - """ - #Check to see what type of file we're working with - if importType == ImportTypes.STEP: - return importStep(fileName) +def importShape(importType, fileName): + """ + Imports a file based on the type (STEP, STL, etc) + :param importType: The type of file that we're importing + :param fileName: THe name of the file that we're importing + """ -#Loads a STEP file into a CQ object + #Check to see what type of file we're working with + if importType == ImportTypes.STEP: + return importStep(fileName) + + +#Loads a STEP file into a CQ.Workplane object def importStep(fileName): - """ + """ Accepts a file name and loads the STEP file into a cadquery shape :param fileName: The path and name of the STEP file to be imported """ #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") + #Make sure that we extract all the solids + solids = [] + for solid in rshape.Solids: + solids.append(Shape.cast(solid)) + + return cadquery.Workplane("XY").newObject(solids) + except: + raise ValueError("STEP File Could not be loaded") diff --git a/cadquery/freecad_impl/shapes.py b/cadquery/freecad_impl/shapes.py index b6c1f8a..be88361 100644 --- a/cadquery/freecad_impl/shapes.py +++ b/cadquery/freecad_impl/shapes.py @@ -49,10 +49,6 @@ """ from cadquery import Vector, BoundBox import FreeCAD - -#from .verutil import fc_import - -#FreeCADPart = fc_import("FreeCAD.Part") import Part as FreeCADPart