cadquery-freecad-module/cadquery/freecad_impl/importers.py
2015-12-01 22:54:36 -05:00

47 lines
1.1 KiB
Python

import cadquery
from .shapes import Shape
import FreeCAD
import Part
class ImportTypes:
STEP = "STEP"
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)
#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)
#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")