[SOLVED] 0.18 DXF import problem

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
jahwobble
Posts: 51
Joined: Sat Sep 21, 2019 1:05 pm

[SOLVED] 0.18 DXF import problem

Post by jahwobble »

Hello, I apologise for posting what has probably been covered before but the search facility returns:
"The following words in your search query were ignored because they are too common words: dxf import draft workbench."
.

Strange that I can't search on the terms that I'm interested in. Anyway, I've tried importing DXF files with the legacy python importer and get the following report output.

Code: Select all

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Program Files\FreeCAD 0.18\Mod\Draft\importDXF.py", line 1587, in insert
    getDXFlibs()
  File "C:\Program Files\FreeCAD 0.18\Mod\Draft\importDXF.py", line 138, in getDXFlibs
    import dxfReader
<class 'SyntaxError'>: invalid syntax (dxfReader.py, line 88)
I've got the latest python files in my Appdata folder (Preferences are set to download the latest).

I'm using v0.18, revision number 16131 on Windows 10 x64. The same DXF files imported OK in 0.17.

If this has been done to death before, I'd be very grateful for a link to the thread. If not, is it a bug that I need to report or am I doing something wrong? Many thanks for any advice.
Last edited by jahwobble on Sat Sep 21, 2019 8:08 pm, edited 1 time in total.
User avatar
Roy_043
Veteran
Posts: 8540
Joined: Thu Dec 27, 2018 12:28 pm

Re: 0.18 DXF import problem

Post by Roy_043 »

jahwobble
Posts: 51
Joined: Sat Sep 21, 2019 1:05 pm

Re: 0.18 DXF import problem

Post by jahwobble »

Thanks Roy. I had the suspicion that despite having ticked "download latest" for the python DXF files, I still didn't have the right ones. Well, the problem is now solved. Nosing around in the Addon Manager, I spotted the dxf library addon and, after installing it, the import worked fine. :)

Image
Attachments
Addons.png
Addons.png (10.83 KiB) Viewed 2588 times
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: 0.18 DXF import problem

Post by vocx »

jahwobble wrote: Sat Sep 21, 2019 1:28 pm ...

Code: Select all

<class 'SyntaxError'>: invalid syntax (dxfReader.py, line 88)
...
This indicates that the problem is in the dxfReader.py file that is downloaded, not in FreeCAD itself.

This is the contents

Code: Select all

 86       def run(self, cargo=None):
 87                 if not self.startState:
 88                         raise InitializationError(
 89                                   "must call .set_start() before .run()")
As I see, the problem is with line 89. In general, the entire code indents using tabs. However, line 89, as well as 92, mixes tabs with spaces (4 tabs and 2 spaces). In Python 3, this raises a syntax error because the indentation depends on how the tab is interpreted, that is, the indentation level with tabs and spaces is ambiguous.

I think FreeCAD downloads dxfReader.py from Yorik's personal GitHub repository. So, maybe I need to submit a patch to this repository, or to the repository of the original authors (Ed Blake et al.).

However, you may try the solution offered as well.
UR_ wrote: Sat Dec 08, 2018 10:30 pm Is this checkbox checked?

Preferences-000124.png
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: 0.18 DXF import problem

Post by vocx »

jahwobble wrote: Sat Sep 21, 2019 8:06 pm ... I spotted the dxf library addon and, after installing it, the import worked fine. :)
Oh, did you solve it? That's good.

However, if the new file that you downloaded still has the mix of tabs + spaces, the error is still there and should be corrected.

Can you check lines 88 to 94 for the presence of tabs and spaces?
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
jahwobble
Posts: 51
Joined: Sat Sep 21, 2019 1:05 pm

Re: [SOLVED] 0.18 DXF import problem

Post by jahwobble »

Hello Vocx, here's a snip showing non-printing characters:

Image

I did indeed check the checkbox suggested and rebooted to make sure the install took full effect, but to no avail. It was the Addon Manager that worked the magic.
Attachments
PYsnip.png
PYsnip.png (9.77 KiB) Viewed 2573 times
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: [SOLVED] 0.18 DXF import problem

Post by vocx »

jahwobble wrote: Sat Sep 21, 2019 8:31 pm ... It was the Addon Manager that worked the magic.
I wonder why it fails when you installed the files yourself and not from the Addon Manager. It seems weird, the error is still there.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
jahwobble
Posts: 51
Joined: Sat Sep 21, 2019 1:05 pm

Re: [SOLVED] 0.18 DXF import problem

Post by jahwobble »

I wonder why it fails when you installed the files yourself and not from the Addon Manager. It seems weird, the error is still there.
Beats the hell out of me. I'm just glad that it works. :D
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: [SOLVED] 0.18 DXF import problem

Post by vocx »

In any case, I submitted pull request #21 to yorikvanhavre/Draft-dxf-importer, from which the Addon Manager downloads the latest DXF libraries.

Its pretty weird, another file, dxfLibrary.py, also mixes tabs and spaces, and seemingly no error is produced.

From the pull request:
vocx wrote: There are other instances of mixing tabs and spaces in dxfLibrary.py. They all happen inside parentheses, or in continuation lines using a backslash \. I think this was done in order to align the code inside the parentheses with the previous line. However, in general this is not a good style because the code only aligns well when the tab width is set to 4 spaces; if the tab width is displayed as 8 spaces, like GitHub does, then it doesn't align the code as the author intended.

This is why it's preferable to be consistent with PEP8 rules, and use only tabs or spaces, for indentation.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
jahwobble
Posts: 51
Joined: Sat Sep 21, 2019 1:05 pm

Re: [SOLVED] 0.18 DXF import problem

Post by jahwobble »

Wise precaution, vocx. It's got me scratching my head - my own Python dabbling showed me how strict it is over syntax and this one is indeed a mystery.

Thanks for your thoughts on and interest in this issue.
Post Reply