Have an Openscad to Freecad conundrum to solve [solved]

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!
keithsloan52
Posts: 1914
Joined: Mon Feb 27, 2012 5:31 pm

Re: Have an Openscad to Freecad conundrum to solve

Postby keithsloan52 » Tue May 11, 2021 9:27 am

keithsloan52 wrote: Tue May 11, 2021 7:08 am
I installed freecad 0.19 at first but trying to install the dependencies of the openscad workbench became a tragedy. A failure. Fought hard to solve the issues that were indicated in the window below each failed attempt.
I REPEAT - THERE ARE NO DEPENDENCIES to install and your post does not show any window.
A thought has just occurred to me - When you say dependencies are you installing FreeCAD from source? and meaning Lex?
If yes then I recommend you switch to using an AppImage https://github.com/FreeCAD/FreeCAD/releases
Or one of realthunders builds https://github.com/realthunder/FreeCAD_ ... 3/releases
Or official downloads https://www.freecadweb.org/downloads.php
Yuri
Posts: 34
Joined: Sun May 09, 2021 1:14 am

Re: Have an Openscad to Freecad conundrum to solve

Postby Yuri » Tue May 11, 2021 3:29 pm

keithsloan52 Thank you.

My path to the openscad exe says.
C:\Program Files\OpenSCAD\openscad.exe
I believe this is correct

The error after load parser below does not occur to me in 0.184 or in 0.19
09:22:18 Start Lex
09:22:18 End Lex
09:22:18 Load Parser
09:22:18 Parser Loaded
09:22:18 Start Parser
09:22:18 Vector
09:22:18 Vector

This is where I get the story about dependencies.
https://wiki.freecadweb.org/OpenSCAD_Module
Dependencies
In FreeCAD 0.19, the Ply (Python-Lex-Yacc) module, which is used to import CSG files, was removed from the FreeCAD source code, as it is a third party library not developed by FreeCAD. As a result, you now need to install Ply before using the OpenSCAD Workbench.


DXFs created with
QCAD Professional
Version:
3.25.0.0 (3.25.0)
Internet:
QCAD.org
Build Date:
Aug 20 2020
Revision:
0fd19c1
Qt Version:
5.13.0
Architecture:
x86_64
Compiler:
MSVC++ 14.0 (2015)


"Insert Walls Cutter" is a layer that I created to groom the qcad to make it readable to freecad. If the parsed rotate extrude from openscad were working I wouldn't have even created that layer. This is to say that the core problem is there without that layer. I will change the color but don't thing that the change is going to remove the core problems. I'll let you know what happens. You could choose to change the color of that layer yourself and see what happens.
After using 3 colors, namely, black, white and red I get "<class 'KeyError'>: -18". It is of note that this error doesn't occur in the 0.184 version. It passes almost all the checks from the report window but I still have problems.

My report window in 0.19 says: (All these checks succeed in 0.184 so that I get the objects and the booleans invisible but the objects are there. I see asteriscs sometimes telling me what Happened)
09:22:18 Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\FreeCAD 0.19\Mod\OpenSCAD\importCSG.py", line 119, in open
processcsg(tmpfile)
File "C:\Program Files\FreeCAD 0.19\Mod\OpenSCAD\importCSG.py", line 177, in processcsg
result = parser.parse(f.read())
File "C:\Program Files\FreeCAD 0.19\bin\lib\site-packages\ply\yacc.py", line 333, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "C:\Program Files\FreeCAD 0.19\bin\lib\site-packages\ply\yacc.py", line 1120, in parseopt_notrack
p.callable(pslice)
File "C:\Program Files\FreeCAD 0.19\Mod\OpenSCAD\importCSG.py", line 752, in p_import_file1
p[0] = [process_import_file(filen,ext,p[3]['layer'])]
File "C:\Program Files\FreeCAD 0.19\Mod\OpenSCAD\importCSG.py", line 770, in process_import_file
obj=processDXF(fname,layer)
File "C:\Program Files\FreeCAD 0.19\Mod\OpenSCAD\importCSG.py", line 834, in processDXF
face = importDXFface(filename,layer,doc)
File "C:\Program Files\FreeCAD 0.19\Mod\OpenSCAD\OpenSCAD2Dgeom.py", line 485, in importDXFface
layers = importDXF.processdxf(doc,filename,False,False) or importDXF.layers
File "C:\Program Files\FreeCAD 0.19\Mod\Draft\importDXF.py", line 2212, in processdxf
color = tuple(dxfColorMap.color_map[layer.color])
<class 'KeyError'>: -18
It seems that the class error -18 is a thing other than a color related issue as I get it regardless of color.

I downloaded the 0.19 version from where you suggested and now I'm downloading the 0.192 to see what happens. I'm not too optimistic.
I get the same in the report window with the 0.192
keithsloan52
Posts: 1914
Joined: Mon Feb 27, 2012 5:31 pm

Re: Have an Openscad to Freecad conundrum to solve

Postby keithsloan52 » Tue May 11, 2021 3:32 pm

Okay I loaded the dxf file into LibreCAD and saved as DXF R14 format, which solved the colour issue, but when I do a test for one layer with OpenSCAD workbench addElements and cut and plasted

Code: Select all

group() { import(file = "/tmp/Insert.dxf", layer = "Insert Walls", origin = [0, 0], scale = 1, convexity = 6, $fn = 0, $fa = 12, $fs = 2, timestamp = 1620713944);
}
It tries to bring in the whole dxf file not just the 'Insert Walls' layer. Don't know if saving for one of the other levels ( it offers 2007, 2004, 2000, R14, R12 ) would be more successful in just bringing in one layer or whether there is a bug with Draft workbenches importDXF.py which is what the OpenSCAD importer uses for reading in DXF files.

Maybe the OP could perform a workaround by placing each layer in a separate dxf file
keithsloan52
Posts: 1914
Joined: Mon Feb 27, 2012 5:31 pm

Re: Have an Openscad to Freecad conundrum to solve

Postby keithsloan52 » Tue May 11, 2021 3:44 pm

Yuri wrote: Tue May 11, 2021 3:29 pm This is where I get the story about dependencies.
https://wiki.freecadweb.org/OpenSCAD_Module
Dependencies
In FreeCAD 0.19, the Ply (Python-Lex-Yacc) module, which is used to import CSG files, was removed from the FreeCAD source code, as it is a third party library not developed by FreeCAD. As a result, you now need to install Ply before using the OpenSCAD Workbench.
Ply (Python-Lex-Yacc) module was initially supplied in Mod/OpenSCAD and was removed as a result of it being subsequently used by other parts of FreeCAD. If I install one of the AppImage versions of FreeCAD it is installed, so me thinks maybe the wiki is in error - Fake news. FreeCAD uses a lot of libraries not developed by FreeCAD like OCC, Coin etc etc.
Last edited by keithsloan52 on Tue May 11, 2021 3:51 pm, edited 1 time in total.
keithsloan52
Posts: 1914
Joined: Mon Feb 27, 2012 5:31 pm

Re: Have an Openscad to Freecad conundrum to solve

Postby keithsloan52 » Tue May 11, 2021 3:49 pm

Yuri wrote: Tue May 11, 2021 3:29 pm keithsloan52 Thank you.

DXFs created with
QCAD Professional
Version:
3.25.0.0 (3.25.0)
Internet:
QCAD.org
Build Date:
Aug 20 2020
Revision:
0fd19c1
Qt Version:
5.13.0
Architecture:
x86_64
Compiler:
MSVC++ 14.0 (2015)
Does QCAD have any options for which version of DXF it exports? The error you are seeing is down to a colour problem, if I open with LibreCAD and save as DXF 14 version I get passed the colour problem, but then falls down trying to bring in the whole file rather than just the requested layer.
keithsloan52
Posts: 1914
Joined: Mon Feb 27, 2012 5:31 pm

Re: Have an Openscad to Freecad conundrum to solve

Postby keithsloan52 » Tue May 11, 2021 3:58 pm

Yuri wrote: Tue May 11, 2021 3:29 pm
File "C:\Program Files\FreeCAD 0.19\Mod\Draft\importDXF.py", line 2212, in processdxf
color = tuple(dxfColorMap.color_map[layer.color])
<class 'KeyError'>: -18
It seems that the class error -18 is a thing other than a color related issue as I get it regardless of color.
No its definitely a colour problem in that it is failing in colour processing code. You may not be able to effect by changing the colour
in the dxf file, but by changing the version of DXF being exported.
Yuri
Posts: 34
Joined: Sun May 09, 2021 1:14 am

Re: Have an Openscad to Freecad conundrum to solve

Postby Yuri » Tue May 11, 2021 9:10 pm

I tried dxf R32 and freecad threw keyvalue error -9 in the report window. I could test the hypo that I may be accomplished if I save separate dxfs with each layer but note:

How do you explain that I have been able to go through all the checks in version 0.184. I have been able to process simpler parts with some layers too. Not too simple in the end regarding the layers.

The 0.184 may have some of the answers as opposed to the 0.192 that is stuck in the report window and not giving me anything other than empty folders.

The dependencies, I suppose I have in the 0.192 version because of what you say and because I'm getting the same reports as you are.

In my view, the 0.184 has a leap forward considering that it does not stop with a lot of errors shown in the report window.
keithsloan52
Posts: 1914
Joined: Mon Feb 27, 2012 5:31 pm

Re: Have an Openscad to Freecad conundrum to solve

Postby keithsloan52 » Tue May 11, 2021 10:11 pm

Yuri wrote: Tue May 11, 2021 9:10 pm I tried dxf R32 and freecad threw keyvalue error -9 in the report window. I could test the hypo that I may be accomplished if I save separate dxfs with each layer but note:

How do you explain that I have been able to go through all the checks in version 0.184. I have been able to process simpler parts with some layers too. Not too simple in the end regarding the layers.

The 0.184 may have some of the answers as opposed to the 0.192 that is stuck in the report window and not giving me anything other than empty folders.

The dependencies, I suppose I have in the 0.192 version because of what you say and because I'm getting the same reports as you are.

In my view, the 0.184 has a leap forward considering that it does not stop with a lot of errors shown in the report window.
I just tried with

Code: Select all

OS: macOS 10.15
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16146 (Git)
Build type: Release
Branch: (HEAD detached at 0.18.4)
Hash: 980bf9060e28555fecd9e3462f68ca74007b70f8
Python version: 3.6.7
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)
And got in Report Window

Code: Select all

ImportCSG Version 0.6a
Start Lex
End Lex
Load Parser
WARNING: (<class 'ply.yacc.VersionError'>, VersionError('yacc table file version is out of date',), <traceback object at 0x7fb6413a3f88>)
WARNING: Token 'WORD' defined, but not used
WARNING: Token 'DOT' defined, but not used
WARNING: There are 2 unused tokens
Unable to create 'parsetab.py'
[Errno 30] Read-only file system: 'parsetab.py'
Parser Loaded
Start Parser
Vector
Vector
Vector
Vector
Matrix
('angle', '-100.744')
('convexity', '6')
('$fn', '0')
('$fa', '12')
('$fs', '2')
('file', 'Insert.dxf')
('layer', 'Insert Walls')
2d Point
('origin', [0.0, 0.0])
('scale', '1')
('convexity', '6')
('$fn', '0')
('$fa', '12')
('$fs', '2')
('timestamp', '1620713944')
Import File
Importing : Insert.dxf Layer : Insert Walls
Process DXF file
File Name : Insert
Layer : Insert Walls
PathName : /Users/keithsloan/Downloads
DXF Full path : /Users/keithsloan/Downloads/Insert.dxf
Loading Mesh module... done
opening /Users/keithsloan/Downloads/Insert.dxf...
drawing 86 lines...
drawing 3 polylines...
drawing 46 arcs...
Joining geometry...
138 edges to join
drawing 20 circles...
skipping texts...
skipping dimensions...
skipping points...
skipping leaders...
skipping hatches...
skipping *blocks...
done processing
successfully imported /Users/keithsloan/Downloads/Insert.dxf
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Applications/FreeCAD_0.18.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 92, in open
    processcsg(filename)
  File "/Applications/FreeCAD_0.18.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 143, in processcsg
    result = parser.parse(f.read())
  File "/Applications/FreeCAD_0.18.app/Contents/Resources/Mod/OpenSCAD/ply/yacc.py", line 265, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/Applications/FreeCAD_0.18.app/Contents/Resources/Mod/OpenSCAD/ply/yacc.py", line 971, in parseopt_notrack
    p.callable(pslice)
  File "/Applications/FreeCAD_0.18.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 694, in p_import_file1
    p[0] = [process_import_file(filen,ext,p[3]['layer'])]
  File "/Applications/FreeCAD_0.18.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 712, in process_import_file
    obj=processDXF(fname,layer)
  File "/Applications/FreeCAD_0.18.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 776, in processDXF
    face = importDXFface(filename,layer,doc)
  File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/OpenSCAD_Alt_Import/OpenSCAD2Dgeom.py", line 494, in importDXFface
    raise ValueError('import of layer %s failed' % layer)
<class 'ValueError'>: import of layer Insert Walls failed
In the View Window I have
3BAC839B-4CF9-4BFC-9DD5-A71563F27B3B_4_5005_c.jpeg
3BAC839B-4CF9-4BFC-9DD5-A71563F27B3B_4_5005_c.jpeg (27.37 KiB) Viewed 698 times
Which looks to me like it imported the whole DXF file.
Maybe it does that then should reduce to just the required layer I don't know.

I think it is worth trying to save 'Insert Walls' as a separate dxf file and trying with that as a first step. You can worry about the other layers after that experiment.
How do you explain that I have been able to go through all the checks in version 0.184. I have been able to process simpler parts with some layers too. Not too simple in the end regarding the layers.
Maybe differences with DXF import preferences?
Maybe changes to Draft importDXF.py?
keithsloan52
Posts: 1914
Joined: Mon Feb 27, 2012 5:31 pm

Re: Have an Openscad to Freecad conundrum to solve

Postby keithsloan52 » Tue May 11, 2021 10:16 pm

Yuri wrote: Tue May 11, 2021 9:10 pm I tried dxf R32 and freecad threw keyvalue error -9 in the report window. I could test the hypo that I may be accomplished if I save separate dxfs with each layer but note:
R32 is the latest version it supports, you will probably have more success with an earlier version. I would start with R14 and work up.
I say R14 as that fixed the colour for me with LibreCAD.
DWG and DXF: read and write support for format versions:
R2.5 (read only)
R2.6 (read only)
R9 (DWG read only)
R10 (DWG read only)
R11
R12 (LT2)
R13
R14 (LT98/LT97)
R15 (2000/LT2000)
R18 (2004/LT2004)
R21 (2007/LT2007)
R24 (2010)
R27 (2013)
R32 (2018)
jmaustpc
Posts: 11037
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Have an Openscad to Freecad conundrum to solve

Postby jmaustpc » Wed May 12, 2021 1:08 am

These are the preferences that Keith is referring to.
Screenshot_20210512_110115.png
Screenshot_20210512_110115.png (134.09 KiB) Viewed 670 times
There are two dxf importers in FreeCAD, the Legacy importer was written in Python, the newer importer is written in C++. Generally if one doesn't work as expected then try the other. I think the Legacy import still supports more things than the newer one. For simple dxf drawings any difference in speed is likely to be irrelevant.

This is the setting to switch between the two different dxf importers in FreeCAD 0.19.
Screenshot_20210512_110145.png
Screenshot_20210512_110145.png (9.73 KiB) Viewed 670 times