Merge branch 'master' into sphinx_branch
This commit is contained in:
commit
9b0fa9da83
|
@ -4,6 +4,10 @@ from .shapes import Shape
|
||||||
|
|
||||||
import FreeCAD
|
import FreeCAD
|
||||||
import Part
|
import Part
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import urllib as urlreader
|
||||||
|
import tempfile
|
||||||
|
|
||||||
class ImportTypes:
|
class ImportTypes:
|
||||||
STEP = "STEP"
|
STEP = "STEP"
|
||||||
|
@ -31,9 +35,9 @@ 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
|
||||||
:param fileName: The path and name of the STEP file to be imported
|
:param fileName: The path and name of the STEP file to be imported
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#Now read and return the shape
|
#Now read and return the shape
|
||||||
try:
|
try:
|
||||||
|
#print fileName
|
||||||
rshape = Part.read(fileName)
|
rshape = Part.read(fileName)
|
||||||
|
|
||||||
#Make sure that we extract all the solids
|
#Make sure that we extract all the solids
|
||||||
|
@ -44,3 +48,24 @@ def importStep(fileName):
|
||||||
return cadquery.Workplane("XY").newObject(solids)
|
return cadquery.Workplane("XY").newObject(solids)
|
||||||
except:
|
except:
|
||||||
raise ValueError("STEP File Could not be loaded")
|
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")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user