-
Notifications
You must be signed in to change notification settings - Fork 56
Conversation
…or urllib.open() function......, not work properly....
Hi, thanks for the contribution! I'll review and work on this tonight. I would like to propose some changes. For one, I'd like to add this As a part of adding this, a I'd also like to support (and document )
|
@dcowden I don't find a clean way to support importing from the web and from the file system simultaneously, and I added a new function at last. According to the document, urllib.urlopen could support URLs and local files. If we use urlopen as the unified interface, for local files, we read, save, and again read if the memory file(OR stream file) is not supported by the Part.read() function. My code is not perfect at all, so you can change anything as you want. |
@hyOzd You are correct, FreeCAD and thus CadQuery are Python 2.7 only. @huskier I have an example of using the tempfile module in our CadQuery module for FreeCAD. https://github.com/jmwright/cadquery-freecad-module/blob/master/CadQuery/Gui/Command.py#L162 |
@huskier, I agree with hyOzd: we do not need the python 3 checks ( python 3x is not supported at all ), and using the tempfile module would make more sense here. Also, and on a more 'interesting' note, lets go ahead and provide a way to access these directly off of the cadquery namespace. We need to avoid adding methods that expose the freecad_impl package. I think we can import 'importers into the cadquery namespace init, so that we can do: cadquery.importers.importStep... Would you mind adding that also? I realize that we have a lot of code floating around using freecad_impl.exporters-- i think that has the same issue. id rather those be cadquery.exporters, or, better yet, for export i'd like to provide that as a method on a cq object, so you can do: Workplane('XY').box(1,3,3).exportStep('filename') |
@huskier, now that i look, we already have the necesary import in init: from cadquery import importers |
…pfile module from the python std library; 3. NOTE: the suffix parameter in the tempfile.NamedTemporaryFile() function is a must, since Part.read need the suffix parameter......
The updated pull request:
|
Thanks for the contribution! |
Import a STEP file from the web
This pull request adds a new function importStepFromURL(url), which will firstly download a STEP file from the web, then save the file into a OS's temp directory, finally import the STEP from the temp directory.
Now, I use the tempfile module from the python std library for the temporary file.
NOTE: the suffix=".step" parameter in the tempfile.NamedTemporaryFile() function is a must, since Part.read need the suffix parameter.
If Part.read() could support memory file reading, we do not need to save the file into disk at all. I hope CQ could support stream-like or memory-file-like file read and write for further other operations.
Here is an example in FreeCAD: