Add a new function importStepFromURL(url) to import STEP file from the web...
This commit is contained in:
parent
f7fcf9bd58
commit
10209482b7
|
@ -24,8 +24,9 @@ from .shapes import Shape
|
||||||
|
|
||||||
import FreeCAD
|
import FreeCAD
|
||||||
import Part
|
import Part
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
|
||||||
if sys.version > '3':
|
if sys.version > '3':
|
||||||
PY3 = True
|
PY3 = True
|
||||||
|
@ -69,22 +70,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
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if isURL(fileName):
|
|
||||||
url = fileName
|
|
||||||
webFile = urlreader.urlopen(url)
|
|
||||||
localFileName = url.split('/')[-1]
|
|
||||||
localFile = open(localFileName, 'w')
|
|
||||||
if PY3:
|
|
||||||
localFile.write(webFile.read().decode('utf-8'))
|
|
||||||
else:
|
|
||||||
localFile.write(webFile.read())
|
|
||||||
webFile.close()
|
|
||||||
localFile.close()
|
|
||||||
fileName = localFileName
|
|
||||||
|
|
||||||
#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
|
||||||
|
@ -95,3 +83,33 @@ 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)
|
||||||
|
if webFile.getcode
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
localFileName = os.environ['TEMP']+url.split('/')[-1]
|
||||||
|
else:
|
||||||
|
localFileName = "/tmp/"+url.split('/')[-1]
|
||||||
|
localFile = open(localFileName, 'w')
|
||||||
|
if PY3:
|
||||||
|
localFile.write(webFile.read().decode('utf-8'))
|
||||||
|
else:
|
||||||
|
localFile.write(webFile.read())
|
||||||
|
webFile.close()
|
||||||
|
localFile.close()
|
||||||
|
fileName = localFileName
|
||||||
|
|
||||||
|
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 from the URL: " + url + " Could not be loaded")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user