DXF legacy python export (with colors) fails

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
CoContrivances
Posts: 7
Joined: Wed Dec 08, 2021 8:30 am

DXF legacy python export (with colors) fails

Post by CoContrivances »

Hello, I have a project where I really need to export a 2-D DXF file with line colors intact. It's so that a cardboard stamping shop knows which lines are for cuts and which for creases etc., on a somewhat complicated design. As I understand, color export only works with the legacy python DXF exporter. I'm using FreeCAD 0.20.1 on a Mac running Ventura.

I tried to change the settings to legacy python export and to automatically download the DXF libraries, but it fails to find the libraries.
Then it ends the export attempt with the error cannot create 'N4Base19ProgressIndicatorPyE' instances
I tried to follow the instructions for manual download https://github.com/yorikvanhavre/Draft-dxf-importer, and I put the files in the specified folder <home> —> Library —> Preferences —> FreeCAD, but it doesn't change anything. Doesn't help if I move the files to the Macro sub-folder either. Doesn't help to quit and re-start FreeCAD.
Also I ran the command to find out which version of dxflib it's expecting, and it says 1.4. But what's available from the manual download page is 1.39.
(Also, every time I switch settings from legacy python export to not or back, it wipes out the Sketcher line colors in my part file.)

Anyone have an idea on how to get color DXF export working? I had the same problems on FreeCAD version 20.
(Pardon if this topic is covered elsewhere; the search dialog wouldn't let me use the terms "dxf" and "export" because they're "too common.")
I also tried another freeware CAD package called SolveSpace to re-add the DXF line colors, but it's not really usable and it messes up the DXF line positions.
CoContrivances
Posts: 7
Joined: Wed Dec 08, 2021 8:30 am

Re: DXF legacy python export (with colors) fails

Post by CoContrivances »

Full version info:
OS: macOS 10.16
Word size of FreeCAD: 64-bit
Version: 0.20.1.29410 (Git)
Build type: Release
Branch: (HEAD detached at 0.20.1)
Hash: f5d13554ecc7a456fb6e970568ae5c74ba727563
Python 3.10.5, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.2
Locale: C/Default (C)
Last edited by CoContrivances on Thu Nov 24, 2022 5:23 am, edited 1 time in total.
CoContrivances
Posts: 7
Joined: Wed Dec 08, 2021 8:30 am

Re: DXF legacy python export (with colors) fails

Post by CoContrivances »

After trying to export, here's what's in the Report View window:

Code: Select all

21:18:17  DVP::extractFaces - View -Can't make faces from projected edges
21:18:17  DVP::extractFaces - View -Can't make faces from projected edges
21:18:35  DXF libraries not found. Trying to download...
21:18:35  Traceback (most recent call last):
  File "<string>", line 8, in <module>
  File "/Applications/FreeCAD.app/Contents/Resources/Mod/Draft/importDXF.py", line 3626, in export
    getDXFlibs()
  File "/Applications/FreeCAD.app/Contents/Resources/Mod/Draft/importDXF.py", line 200, in getDXFlibs
    errorDXFLib(gui)
  File "/Applications/FreeCAD.app/Contents/Resources/Mod/Draft/importDXF.py", line 118, in errorDXFLib
    progressbar = Base.ProgressIndicator()
<class 'TypeError'>: cannot create 'N4Base19ProgressIndicatorPyE' instances
and the Python console:

Code: Select all

Python 3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 07:09:31) [Clang 13.0.1 ] on darwin
Type 'help', 'copyright', 'credits' or 'license' for more information.
>>> Gui.runCommand('Std_Workbench',19)
>>> Gui.runCommand('Std_ViewStatusBar',1)
>>> Gui.runCommand('Std_About',0)
>>> MRU="0"
>>> with open('/Applications/FreeCAD.app/Contents/Resources/share/Mod/Start/StartPage/LoadMRU.py') as file:
>>> 	exec(file.read())
>>> FreeCAD.openDocument('/Users/*****/Documents/engineering/air cleaners/Flow Easel/fan box flat pattern.FCStd')
>>> # App.setActiveDocument("fan_box_flat_pattern")
>>> # App.ActiveDocument=App.getDocument("fan_box_flat_pattern")
>>> # Gui.ActiveDocument=Gui.getDocument("fan_box_flat_pattern")
>>> Gui.runCommand('Std_OrthographicCamera',1)
>>> # Gui.Selection.addSelection('fan_box_flat_pattern','Sketch004')
>>> # Gui.Selection.addSelection('fan_box_flat_pattern','Sketch005')
>>> # Gui.Selection.addSelection('fan_box_flat_pattern','Sketch006')
>>> # Gui.Selection.addSelection('fan_box_flat_pattern','Sketch007')
>>> # Gui.Selection.addSelection('fan_box_flat_pattern','Sketch008')
>>> ### Begin command Std_Export
>>> __objs__=[]
>>> __objs__.append(FreeCAD.getDocument("fan_box_flat_pattern").getObject("Sketch004"))
>>> __objs__.append(FreeCAD.getDocument("fan_box_flat_pattern").getObject("Sketch005"))
>>> __objs__.append(FreeCAD.getDocument("fan_box_flat_pattern").getObject("Sketch006"))
>>> __objs__.append(FreeCAD.getDocument("fan_box_flat_pattern").getObject("Sketch007"))
>>> __objs__.append(FreeCAD.getDocument("fan_box_flat_pattern").getObject("Sketch008"))
>>> import importDXF
>>> importDXF.export(__objs__,u"/Users/*****/Documents/engineering/air cleaners/Flow Easel/101-0001-02 fan box flat pattern.dxf")
>>> 
>>> ### End command Std_Export
>>> 
CoContrivances
Posts: 7
Joined: Wed Dec 08, 2021 8:30 am

Re: DXF legacy python export (with colors) fails

Post by CoContrivances »

Correction, it is dxflibrary.py version 1.4 after all (from 2015)
CoContrivances
Posts: 7
Joined: Wed Dec 08, 2021 8:30 am

Re: DXF legacy python export (with colors) fails

Post by CoContrivances »

I ended up using LibreCAD to apply DXF colors. So, no urgency here, I worked it out.
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: DXF legacy python export (with colors) fails

Post by heda »

good that you found a way to do it

here is what i got with first use of legacy exporter...

Code: Select all

DXF libraries not found. Trying to download...
downloading https://raw.githubusercontent.com/yorikvanhavre/Draft-dxf-importer/1.40/dxfColorMap.py ...
downloading https://raw.githubusercontent.com/yorikvanhavre/Draft-dxf-importer/1.40/dxfImportObjects.py ...
downloading https://raw.githubusercontent.com/yorikvanhavre/Draft-dxf-importer/1.40/dxfLibrary.py ...
downloading https://raw.githubusercontent.com/yorikvanhavre/Draft-dxf-importer/1.40/dxfReader.py ...
successfully exported /home/xyz/Documents/cad/dxf color/dxf color2.dxf
successfully exported /home/xyz/Documents/cad/dxf color/dxf color3.dxf
so download worked and dxf's read into librecad with colors

in other words, not reproducible on my box...

something going on with apples?
something with py 3.10?
also, "DVP::extractFaces - View -Can't make faces from projected edges" - what are you exporting to dxf?
User avatar
Roy_043
Veteran
Posts: 8540
Joined: Thu Dec 27, 2018 12:28 pm

Re: DXF legacy python export (with colors) fails

Post by Roy_043 »

Have you tested with a sketch?:
CoContrivances wrote: Thu Nov 24, 2022 5:04 am (Also, every time I switch settings from legacy python export to not or back, it wipes out the Sketcher line colors in my part file.)
Using the legacy Python exporter I can't get the color of a sketch to export, and the line and point colors of the sketch are reverted to white. This problem does not occur for Draft objects.

Code: Select all

OS: Windows 8.1 Version 6.3 (Build 9600)
Word size of FreeCAD: 64-bit
Version: 0.21.31058 (Git)
Build type: Release
Branch: master
Hash: e6c53d8642af36ce7d738ab6058b063ec58e0859
Python 3.10.6, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: Dutch/Netherlands (nl_NL)
Installed mods: 
Post Reply