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

Import a STEP file from the web #128

Merged
merged 5 commits into from
Dec 2, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")