DXF export of Drawing pages

Info about new implemented features, classes, modules or APIs. Might get technical!
User avatar
yorik
Site Admin
Posts: 8561
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

DXF export of Drawing pages

Postby yorik » Fri Aug 15, 2014 10:08 pm

I finally recoded the Draft stuff that exports Drawing pages in git commit b33d8f6, and there are huge progresses:

Image

Image

It is still pretty simple to use: Create some objects, create a page, the select the page and File->Export->DXF.

There are three important things to know:

1)Not all Drawing views are supported. At the moment, only Part views, Draft views made with the Draft->Drawing tool, Arch views made by using the Draft->Drawing button with an Arch section plane selected and Drawing Annotations. The others (Clipping views, and SVG-based custom views) are not (yet) supported.

2) The template is exported only if a DXF template with the same name as the SVG one is found in he same directory. Otherwise, the template is simply not considered. I created DXF templates for the two default FreeCAD A3 and A4 templates. Creating a DXF template from an existing SVG template is not difficult, I'll explain below.

3) The exported DXF code is of version DXFr12. This version doesn't support some entities that didn't exist at that time, such as Splines and Ellipses. Such edge types are exported anyway (yeah, hacky, I know). Some applications (LibreCAD) will gladly open these "unorthodox" files, others (draftsight) will open them but not import the "bad" objects, and some others (autocad) will simply not open the file. Later on I'll work further on that problem.

Here is a more complex example, with a custom template and my IFC test house:

Image

Image

The export operation leaves the template at 1:1 scale, and turns each view into a block, then scales, places and rotates that block according to what's in the drawing page. I thought it's the smartest solution. So the result is scaled the same way as in FreeCAD, but since they are blocks, it's a piece of cake to scale everything back to 1:1. For example, below I simply scaled everything up, made sure all blocks had (1,1,1) scale, exploded them, and made adjustments to dimension styles, that's 5 minutes work:

Image

The DXF template system might seem redundant (yet another template?) but I found it the most efficient and reliable way. There is basically no good SVG->DXF conversion tool available, everything I found is complicated and very error-prone, this seemed to me the most controllable solution with the best output.

Creating a DXF template is easy if you already have an SVG template. I'll add better instructions on the wiki, but basically it involves:
- Open the template in Inkscape
- Export it as DXF, choosing "px" as the unit
- Open the exported DXF in a DXF app such as LibreCAD
- Adjust/add/fix everything you want, make sure the top left corner of the template is at (0,0) (so the coordinates match those of the Drawing page)
- If needed, change all texts to match the editable text names in the SVG template
- Save as DXF r12 in the same folder and with the same name as the corresponding SVG template

Then the little modification you need to do in a text editor:
- Add a "$blocks" line at the end of the blocks section (just before the ENDSEC)
- Add a "$entities" line at the end of the entities section (just before the ENDSEC)

This last modifications unfortunately turns the template unopenable, I still didn't find how to solve that.

Ah there is one important change for who was using the Drawing.projectToDXF(shape) function (but I think that will be very few people, if any). Before, that function returned a complete DXF file description, with a complete file header. This seemed not correct to me, though, so I changed this function to return only the DXF code corresponding to the shape, the same way as projectToSVG(). This way, you can join several shapes into one file.

So if you were using this function before, you must add a minimal DXF header: change all occurences of:

Code: Select all

dxfcode = Drawing.projectToDXF(myshape)

with

Code: Select all

dxfcode = "0\n0\nSECTION\n2\nENTITIES\n" + Drawing.projectToDXF(myshape) + "0\nENDSEC\n0\nEOF"

to make it give the same result as before.

I think that's it for now, not perfect yet, but already much better, no?
User avatar
saso
Posts: 608
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: DXF export of Drawing pages

Postby saso » Fri Aug 15, 2014 11:23 pm

are the lineweights in the drawing set manually or auto, because the roof in the section on the right seem a bit wrong, in draftsight also the two ellipse columns ;)

but great to see this improvements...
User avatar
yorik
Site Admin
Posts: 8561
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: DXF export of Drawing pages

Postby yorik » Sat Aug 16, 2014 12:05 am

Heh you are right... I hadn't noticed the missing columns in the elevation view :) There are still some glitches here and there.
The lineweights are decided by the Arch section planes view, it performs a cut between the model and the section plane, then retains the sections and shows them on top of the rest with a thicker lineweight (you can configure that in the arch prefs), something must not have worked correctly there.
User avatar
saso
Posts: 608
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: DXF export of Drawing pages

Postby saso » Sat Aug 16, 2014 12:27 am

yorik wrote:The lineweights are decided by the Arch section planes view, it performs a cut between the model and the section plane, then retains the sections and shows them on top of the rest with a thicker lineweight (you can configure that in the arch prefs), something must not have worked correctly there.


i thought so, it is why i thought it would be good to point it out... the roof slab (in section, left of the circled window and top most line of the small slab wall on the right) seems to be wrong in both freecad drawing view and in draftsight (the difference in librecad is not clear enough in this pictures). the two ellipse columns (in floor plan) however seem to be correct (bold) in freecad but wrong (blue) in draftsight... just as an interesting observation if you decide to look at it, what is going on :)
mrlukeparry
Posts: 652
Joined: Fri Jul 22, 2011 8:37 pm
Contact:

Re: DXF export of Drawing pages

Postby mrlukeparry » Sun Aug 24, 2014 9:48 am

yorik, did you manage to fix the arc orientation for good now?

I still don't think the solution I had for using b-splines for creating arcs is a good solution when exporting.
User avatar
yorik
Site Admin
Posts: 8561
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: DXF export of Drawing pages

Postby yorik » Mon Aug 25, 2014 2:58 pm

There are still some problems with arcs export... But I didn't fully look into it yet... I still couldn't isolate some good test cases