Help with creating macro for export to DXF and SVG.

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!
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Help with creating macro for export to DXF and SVG.

Post by triplus »

When I run the standalone dxf macro, then I get only one view. Is that right or should it be like the svg file?
Yes DXF is usually used for manufacturing purposes (export for laser cutting or milling for example). It's quite standard interchangeable drawing format in CAD world too that much is true but for the drawing part in FreeCAD currently SVG is primary format/strategy. I guess new Drawing Workbench being made ATM won't be based that much around SVG anymore and probably when it lands this macro will be obsolete.

But currently i use SVG for drawings and DXF for manufacturing in FreeCAD and if possible i will continue to do it like this in the future too!
Last edited by triplus on Sun Sep 01, 2013 8:01 pm, edited 1 time in total.
User avatar
ralvejd
Posts: 58
Joined: Wed Feb 20, 2013 10:31 pm
Location: Sweden

Re: Help with creating macro for export to DXF and SVG.

Post by ralvejd »

Thanks for the reply Triplus, I was hoping to get all views in one dxf file.
sorry for my outrageous English, but I have a bad excuse
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Help with creating macro for export to DXF and SVG.

Post by triplus »

Actually you can do that easily with DXF standalone macro too:

Code: Select all

import os
homepath = os.path.expanduser("~")
selection = FreeCADGui.Selection.getSelection()
obj = selection[0]
filename = homepath + os.sep + obj.Label.encode("utf-8") + ".dxf"
import importDXF
importDXF.export(selection,filename)
Just create Drawing and instead of selecting individual object in tree view just select created Drawing instead and run the macro on it. The result should be drawing exported in DXF format. Probably this is what Yorik thought i was after but i was only after DXF (single view) for manufacturing purposes and not DXF for drawing itself where i use SVG.

There might and probably will be issues you will encounter like:
-Distorted isometric view.
-Default A3 template used in Macro Automatic Drawing it's currently too complex for importDXF to handle it. For quick test select created Drawing and under properties (Data tab) change template to A3_Landscape_ISO7200.svg and then press CTRL + R to refresh the template. After that use macro on created Drawing and you should have drawing in DXF format in your home folder.
User avatar
cblt2l
Posts: 155
Joined: Sat May 15, 2010 3:59 am

Re: Help with creating macro for export to DXF and SVG.

Post by cblt2l »

triplus wrote:Actually you can do that easily with DXF standalone macro too:

Code: Select all

import os
homepath = os.path.expanduser("~")
selection = FreeCADGui.Selection.getSelection()
obj = selection[0]
filename = homepath + os.sep + obj.Label.encode("utf-8") + ".dxf"
import importDXF
importDXF.export(selection,filename)
Just create Drawing and instead of selecting individual object in tree view just select created Drawing instead and run the macro on it. The result should be drawing exported in DXF format. Probably this is what Yorik thought i was after but i was only after DXF (single view) for manufacturing purposes and not DXF for drawing itself where i use SVG.

There might and probably will be issues you will encounter like:
-Distorted isometric view.
-Default A3 template used in Macro Automatic Drawing it's currently too complex for importDXF to handle it. For quick test select created Drawing and under properties (Data tab) change template to A3_Landscape_ISO7200.svg and then press CTRL + R to refresh the template. After that use macro on created Drawing and you should have drawing in DXF format in your home folder.
ralvejd, I'm on Wheezy too, but I'm running version 0.14-git2434. I'm not familiar with the python/macro stuff but the code posted above works fine for me (i.e. there is a dwf file with a box)

Try upgrading to the latest wheezy build here https://www.dropbox.com/s/jr62ej2trprb9 ... _amd64.deb

The 0.13 vs 0.14 version mismatch is my fault. :oops: I didn't bump up the version number in the build script so it stayed at 0.13. It should be 0.14.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Help with creating macro for export to DXF and SVG.

Post by triplus »

This is the macro ralvejd had issues with testing on Debian:

viewtopic.php?f=3&t=4457&start=10#p35182

Only the last part (export to DXF file) didn't work but using standalone macro for exporting to DXF did. Test this macro on Debian and after running it there should be one SVG and one DXF file in your home folder if it will work OK if it will not you will only find SVG file!
User avatar
cblt2l
Posts: 155
Joined: Sat May 15, 2010 3:59 am

Re: Help with creating macro for export to DXF and SVG.

Post by cblt2l »

I'm getting both the dfx and the svg, so its either the older freecad rev causing him problems or something on his system is borked. Note, I'm running this from the macro window and not from the python shell.

On a side note, the svg drawing is pretty awesome.
User avatar
ralvejd
Posts: 58
Joined: Wed Feb 20, 2013 10:31 pm
Location: Sweden

Re: Help with creating macro for export to DXF and SVG.

Post by ralvejd »

Hi cblt2l

Tested with the new deb file https://www.dropbox.com/s/jr62ej2trprb9 ... _amd64.deb
And run triplus code
Traceback (most recent call last):
File "/home/isak/Dokument/9_Projekt/cad/FeeCAD/Macro/DxfSvg.FCMacro", line 303, in <module>
import importDXF
File "/usr/Mod/Draft/importDXF.py", line 44, in <module>
import sys, FreeCAD, os, Part, math, re, string, Mesh, Draft, DraftVecUtils, DraftGeomUtils
File "/usr/Mod/Draft/Draft.py", line 4022, in <module>
import DraftSnap
File "/usr/Mod/Draft/DraftSnap.py", line 29, in <module>
import FreeCAD, FreeCADGui, math, Draft, DraftGui, DraftTrackers, DraftVecUtils
File "/usr/Mod/Draft/DraftTrackers.py", line 30, in <module>
from pivy import coin
File "/usr/bin/pivy/__init__.py", line 28, in <module>

File "/usr/bin/pivy/coin.py", line 14, in <module>
<type 'exceptions.ImportError'>: No module named _coin
I then discovered a lot of new problems so I went back to verisionen I used before. One of the errors that occurred is that "Part" missing in preferences.
When I returned to the previous version, "Part" does not exist there either. Not sure if it really was there before in that version, it might disappear in a previous update.

Export to dxf gives me mostly faulty files and time is passing, I will draw up all my parts again in 2D from scratch.

This is quite off topic so would anyone continue to dig into this then it should perhaps be in a new thread?
sorry for my outrageous English, but I have a bad excuse
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Help with creating macro for export to DXF and SVG.

Post by triplus »

I'm getting both the dfx and the svg, so its either the older freecad rev causing him problems or something on his system is borked. Note, I'm running this from the macro window and not from the python shell.
Yes probably it could be something is missing or some path not set... Do you ralvejd by any chance have the possibility to test the package by installing it on fresh installed Debian system?
On a side note, the svg drawing is pretty awesome.
I went with A3 template and 4 standard views but macro can be easily modified (user settings) to adapt to other templates/use cases.
User avatar
ralvejd
Posts: 58
Joined: Wed Feb 20, 2013 10:31 pm
Location: Sweden

Re: Help with creating macro for export to DXF and SVG.

Post by ralvejd »

triplus wrote:Do you ralvejd by any chance have the possibility to test the package by installing it on fresh installed Debian system?
Yes, a new installation of Debian is probably the solution. Right now I have no time for it. I will come back with results when I tested it.
I spend most of my spare time on completion of a gantry router. Thanks everyone who contribute, without FreeCAD would it been difficult.
sorry for my outrageous English, but I have a bad excuse
Post Reply