Made the STEP import function more robust so that it could return a CQ.Workplane object.

This commit is contained in:
Jeremy Wright 2014-12-11 14:35:29 -05:00
parent 4b98b04465
commit e51b54d6c4
4 changed files with 27 additions and 32 deletions

View File

@ -18,9 +18,6 @@
""" """
import math,sys import math,sys
#import FreeCAD
#from .verutil import fc_import
#FreeCAD = fc_import("FreeCAD")
import FreeCAD import FreeCAD
#Turns out we don't need the Part module here. #Turns out we don't need the Part module here.

View File

@ -20,10 +20,8 @@
a string containing the model content. a string containing the model content.
""" """
import cadquery import cadquery
from .shapes import Shape from .shapes import Shape, Compound
#from .verutil import fc_import
# FreeCAD = fc_import("FreeCAD")
# Part = fc_import("FreeCAD.Part")
import FreeCAD import FreeCAD
import Part import Part
@ -34,6 +32,7 @@ class UNITS:
MM = "mm" MM = "mm"
IN = "in" IN = "in"
def importShape(importType, fileName): def importShape(importType, fileName):
""" """
Imports a file based on the type (STEP, STL, etc) Imports a file based on the type (STEP, STL, etc)
@ -45,7 +44,8 @@ def importShape(importType,fileName):
if importType == ImportTypes.STEP: if importType == ImportTypes.STEP:
return importStep(fileName) return importStep(fileName)
#Loads a STEP file into a CQ object
#Loads a STEP file into a CQ.Workplane object
def importStep(fileName): def importStep(fileName):
""" """
Accepts a file name and loads the STEP file into a cadquery shape Accepts a file name and loads the STEP file into a cadquery shape
@ -56,9 +56,11 @@ def importStep(fileName):
try: try:
rshape = Part.read(fileName) rshape = Part.read(fileName)
r = Shape.cast(rshape) #Make sure that we extract all the solids
#print "loadStep: " + str(r) solids = []
#print "Faces=%d" % cadquery.CQ(r).solids().size() for solid in rshape.Solids:
return cadquery.CQ(r) solids.append(Shape.cast(solid))
return cadquery.Workplane("XY").newObject(solids)
except: except:
raise ValueError("STEP File Could not be loaded") raise ValueError("STEP File Could not be loaded")

View File

@ -49,10 +49,6 @@
""" """
from cadquery import Vector, BoundBox from cadquery import Vector, BoundBox
import FreeCAD import FreeCAD
#from .verutil import fc_import
#FreeCADPart = fc_import("FreeCAD.Part")
import Part as FreeCADPart import Part as FreeCADPart