Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Merge f94f9fe into 4c1a91b
Browse files Browse the repository at this point in the history
  • Loading branch information
huskier committed Dec 2, 2015
2 parents 4c1a91b + f94f9fe commit b1445fc
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions cadquery/freecad_impl/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@

import FreeCAD
import Part

import sys
import os
import urllib as urlreader
import tempfile

class ImportTypes:
STEP = "STEP"

Expand All @@ -50,11 +54,11 @@ 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)
#print fileName
rshape = Part.read(fileName)

#Make sure that we extract all the solids
solids = []
Expand All @@ -64,3 +68,24 @@ def importStep(fileName):
return cadquery.Workplane("XY").newObject(solids)
except:
raise ValueError("STEP File Could not be loaded")

#Loads a STEP file from an URL into a CQ.Workplane object
def importStepFromURL(url):
#Now read and return the shape
try:
webFile = urlreader.urlopen(url)
tempFile = tempfile.NamedTemporaryFile(suffix='.step', delete=False)
tempFile.write(webFile.read())
webFile.close()
tempFile.close()

rshape = Part.read(tempFile.name)

#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 from the URL: " + url + " Could not be loaded")

0 comments on commit b1445fc

Please sign in to comment.