DXF Import Stalls
joeborrello opened this issue · 31 comments
I've been trying to import DXF files that I'm generating through OpenSCAD, but the import function just seems to hang up when I try to import a file. Initially, I thought it was due to the number of lines in the DXF files I was using, but I dramatically reduced it down to a few hundred and the issue still persists.
Are you using 'dxfgrabber >= 0.8.0?
What version of pycalculix are you using?
Please update to the version here: https://github.com/spacether/pycalculix/tree/feature/adds_samples_testing
and let me know if your dxf file won't import.
pycalculix version is 0.9.3, so it looks like that needs to be imported.
I'm not sure if I'm actually using dxfgrabber. I haven't seen that library get called anywhere while trying to debug.
dxfgrabber is used under the hood by pycalculix to load in the dfx file and convert its dfx geometry into pycalculix points/lines/arcs/areas/parts
I've been trying to update pycalculix to the latest version through pip/pip3, but it stays on 0.9.3 after I try to upgrade
The newer version is only available on github
So should I just pull this repo and re-install/upgrade?
Try running:
pip3 install git+https://github.com/spacether/pycalculix@feature/adds_samples_testing
That got pycalculix updated to the latest version (0.9.5) but it still just seems to freeze on the importer.load()
command. I'm also not sure how to check my dxfgrabber version.
Run:
python3
import dxfgrabber
dxfgrabber.version
Returns (1, 0, 0)
Can you upload you dxf file here?
Are you able to load it with the dxfgrabber library or the ezdxf library?
github doesn't seem to support DXFs, but here's a link to the file: https://www.dropbox.com/s/p7tejsfbqzag7wf/var-thick_REHex_parametic_low-res.dxf?dl=0
I haven't tried loading the file with just dxfgrabber or ezdxf yet.
Dxf added, zipped it
var-thick_REHex_parametic_low-res.dxf.zip
Should I retry with the zipped dxf?
No, I posted it for traceability
Okay, this is happening because the cad importer assumes that all lines are part of areas, either external or internal lines. It is unable to stitch all of the lines together to form areas and loops infinitely.
By eye the cad file looks good, see its attached image.
@joeborrello is the geometry one area with many bowtie-shaped holes?
At a minimum I need to allow lines to be discarded if they are not part of areas.
I will further investigate why this file is not working.
@spacether yeah, it is a single area with multiple holes.
@joeborrello I have merged a commit into my working branch which fixes the dxf import issue.
You can install it with:
pip3 install git+https://github.com/spacether/pycalculix@feature/adds_samples_testing
May I include your dxf file as a pycalculix example and a test so I can make sure importing this dxf will always work in the future?
@spacether yeah, feel free to include the model as a demo/test. I'll be able to try out the fix later today.
Thanks @joeborrello
You can test your example in the repo at samples/import-dxf-2.py
I'm still having the same problem even after the new install. I'm wondering if this is could be happening because I'm trying to work with the importer in a Jupyter notebook?
I had to slightly adjust the method you used in import-dxf-2.py
in order to get my absolute path in the notebook, so could it be there might be some other functions that aren't getting called the same way as they would be from an IDE?
@joeborrello please make sure that you uninstall pycalculix before you reinstall the latest version.
Did you remove your old version before re-installing it?
Only the version from this commit and later will work for your file:
https://github.com/spacether/pycalculix/tree/a85a8b51e4a2756078c680ffcef27a28e303eb22
Is your file still hanging?
What happens when you cd into the samples directory and run python import-dxf-2.py
?
@spacether I uninstalled the previous version of pycalculix and then installed using the pip3 command you posted earlier, but the file is still hanging in the Jupyter notebook.
Running the example code from the terminal does work for me, however.
Hmm that is very weird. Those dxf files are the same. I wonder what python environment Jupiter notebooks use. What os are you on?
Can you print the pycalculix version from inside your jupiter notebook file? What does it say?
Inside jupyter, I also get 0.9.5
Do some constraints have to be used differently when an imported DXF is used as the model? I tried using .bottom
and .top
to define fixed constraints and got the following error:
AttributeError 'list' oject has not attribute 'bottom'
@spacether any thoughts on what might be causing this .top
/.bottom
error?
Should I open up a different thread for this, since the importing issues are definitely fixed (for everything but Jupyter) now?
@joeborrello are you using part.top and part.bottom? They assumes that the top and bottom lines are horizontal and at a maximum and minimum x values. Looking at the image above, it doesn't look like a part.top or part.bottom will be set because the lines are zig zagging. The best way to do it is using a specific line or point. If you want to continue discussing the constraints, please open up a separate issue on it.
@spacether When I looked back at that part, I realized that might have been the case. I tried running the code for another, rectangular part, which I thought had a horizontal top like at the maximum x, but it still failed. Based on that, my guess is the DXF file isn't being saved and/or imported into pycaclulix perfectly, so what looks like a horizontal line isn't actually flat. I can share this new file I'm working with, if you'd like.
@joeborrello that sounds good. Please open a separate issue with a screenshot and upload of your different file.