TechDraw: export View to DXF

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
wandererfan
Veteran
Posts: 6321
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: TechDraw: export View to DXF

Post by wandererfan »

easyw-fc wrote: Sat Mar 17, 2018 9:50 pm TechDraw.viewPartAsDxf if invoked for the simple ellipse I'm attaching, will produce a wrong output
It looks like the specification of an Ellipse may vary depending on Dxf version. Haven't understood all the details yet.
easyw-fc wrote: it seems the issues I have with TechDraw.viewPartAsDxf are BSpline related...
Wasn't there an issues with BSpline in Drawing::DXFOut recently?
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

Re: TechDraw: export View to DXF

Post by easyw-fc »

wandererfan wrote: Sun Mar 18, 2018 12:58 pm
easyw-fc wrote: Sat Mar 17, 2018 9:50 pm c if invoked for the simple ellipse I'm attaching, will produce a wrong output
It looks like the specification of an Ellipse may vary depending on Dxf version. Haven't understood all the details yet.
just for information, TechDraw.viewPartAsSvg is working fine
wandererfan wrote: Sun Mar 18, 2018 12:58 pm
easyw-fc wrote: it seems the issues I have with TechDraw.viewPartAsDxf are BSpline related...
Wasn't there an issues with BSpline in Drawing::DXFOut recently?
would you mind to point this issue? I've searched at the forum but I haven't found anything...

Moreover the TechDraw.viewPartAsSvg is failing in the same way, but the TechDraw Menu Export as SVG is doing the conversion correctly
Are there two different methods to obtain the output?

Thx again
Maurice
User avatar
wandererfan
Veteran
Posts: 6321
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: TechDraw: export View to DXF

Post by wandererfan »

easyw-fc wrote: Sun Mar 18, 2018 2:09 pm if invoked for the simple ellipse I'm attaching, will produce a wrong output
Some progress on ellipse. Here is your ellipse in LibreCad.
easyw-fc_ellipse.png
easyw-fc_ellipse.png (30.47 KiB) Viewed 1807 times
Note the fussy little changes to the fcOut.dxf file required to make it work! Biggest one is typo, sb ENDSEC not ENDSECT.
fcOut_ellipse.dxf
(181 Bytes) Downloaded 55 times
easyw-fc wrote: it seems the issues I have with TechDraw.viewPartAsDxf are BSpline related...
would you mind to point this issue? I've searched at the forum but I haven't found anything...
Not as recent as I thought: git commit a32972ef2f
easyw-fc wrote: Moreover the TechDraw.viewPartAsSvg is failing in the same way, but the TechDraw Menu Export as SVG is doing the conversion correctly
Are there two different methods to obtain the output?
Yes. The Menu/Gui "Export As Svg" uses a Qt routine to translate what Qt is showing on the screen into SVG. viewPartAsSvg/Dxf use SVGOutput and DXFOutput routines from the Drawing module to translate OCC edges. These 2 routines are very similar except for the actual writing of Svg vs Dxf text.

I'll look into BSplines now.
User avatar
wandererfan
Veteran
Posts: 6321
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: TechDraw: export View to DXF

Post by wandererfan »

easyw-fc wrote: Sun Mar 18, 2018 11:08 am it seems the issues I have with TechDraw.viewPartAsDxf are BSpline related...
Here two files where the dxf export is failing with bsplines (the dxf is the result of a direct export without the shifting)
I don't have any problem exporting views from either file:
pallier_front.png
pallier_front.png (18.45 KiB) Viewed 1796 times
pallier_top.png
pallier_top.png (15.68 KiB) Viewed 1796 times
pallier_front2.png
pallier_front2.png (130.39 KiB) Viewed 1796 times
Different LibreCAD?
LibreCAD_about.png
LibreCAD_about.png (66.78 KiB) Viewed 1796 times
Different OCC?
OS: Linux Mint 18.3 Sylvia
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13397 +1 (Git)
Build type: debug
Branch: edge2edgeDim
Hash: c02ddba1fbc31eeb442c6c71b05b4f244c2f1a0c
Python version: 2.7.12
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: English/Canada (en_CA)
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

Re: TechDraw: export View to DXF

Post by easyw-fc »

wandererfan wrote: Sun Mar 18, 2018 5:27 pm
easyw-fc wrote: Sun Mar 18, 2018 11:08 am it seems the issues I have with TechDraw.viewPartAsDxf are BSpline related...
Here two files where the dxf export is failing with bsplines (the dxf is the result of a direct export without the shifting)
I don't have any problem exporting views from either file:
pallier_front.png
pallier_top.png
pallier_front2.png

Different LibreCAD?
LibreCAD_about.png
Good catch!
Yes, LibreCAD 2.13 compared to LCAD 2.09
I'm viewing the file like you in LibreCAD 2.0.9 in Windows...
:)
I'm going to test it a bit deeper ... Thanks :D
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

Re: TechDraw: export View to DXF

Post by easyw-fc »

wandererfan wrote: Sun Mar 18, 2018 5:27 pm I don't have any problem exporting views from either file:
Hi @wanderfan,
is there a way to obtain a list of TechDraw edges projected onto the page using python?
I was thinking to send them to the DXF FC exporter to test the result...

Code: Select all

importDXF.export(__objs__,u"c:/Temp/TD-test.dxf")
Thx
Maurice
User avatar
wandererfan
Veteran
Posts: 6321
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: TechDraw: export View to DXF

Post by wandererfan »

edit2: this depends on a modified version of viewPartAsDxf()

Some progress:
PageInFC.png
PageInFC.png (31.72 KiB) Viewed 1767 times
PageInLC.png
PageInLC.png (12.76 KiB) Viewed 1767 times
Edit: forgot the script:

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# export an entire Page of DrawViewParts as Dxf

import FreeCAD
import TechDraw

fileSpecDxf = "fcPageOut.dxf"
s = FreeCADGui.Selection.getSelection()
myObj = s[0]
print myObj.Name," / ", myObj.TypeId
dxfStart = "0\nSECTION\n2\nENTITIES\n"
dxfEnd = "0\nENDSEC\n0\nEOF\n"
if (myObj.isDerivedFrom("TechDraw::DrawPage")):
    p = myObj
    pv = myObj.Views
    s = ""
    for v in pv:
        if v.isDerivedFrom("TechDraw::DrawViewPart"):
            s += TechDraw.viewPartAsDxf(v)
        if v.isDerivedFrom("TechDraw::DrawProjGroup"):
            for vv in v.Views:
                if vv.isDerivedFrom("TechDraw::DrawViewPart"):
                    s += TechDraw.viewPartAsDxf(vv)

    dxfFile = open(fileSpecDxf, "w")
    dxfFile.write(dxfStart)
    dxfFile.write(s)
    dxfFile.write(dxfEnd)
    dxfFile.close()
else:
    print("wrong selection")

print "exportPage.py finished"
Last edited by wandererfan on Sun Mar 18, 2018 11:26 pm, edited 2 times in total.
User avatar
wandererfan
Veteran
Posts: 6321
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: TechDraw: export View to DXF

Post by wandererfan »

easyw-fc wrote: Sun Mar 18, 2018 8:57 pm is there a way to obtain a list of TechDraw edges projected onto the page using python?
I was thinking to send them to the DXF FC exporter to test the result...

Code: Select all

importDXF.export(__objs__,u"c:/Temp/TD-test.dxf")
I'll have to think about that one. Nothing jumps out at me. The edges are all stored in the View, but I don't think there is a Python method to access them directly.
User avatar
wandererfan
Veteran
Posts: 6321
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: TechDraw: export View to DXF

Post by wandererfan »

easyw-fc wrote: Sun Mar 18, 2018 8:57 pm is there a way to obtain a list of TechDraw edges projected onto the page using python?
I was thinking to send them to the DXF FC exporter to test the result...

Code: Select all

importDXF.export(__objs__,u"c:/Temp/TD-test.dxf")
As soon as I can figure out what form "__objs__" takes (OCC edge, FC edge, Draft wire, ...), I can build a version of FC where DrawViewPart has a method like "getEdges". But I don't think I can move it to master until 0.17 release shakes out.

I'll build it and act as your service bureau if you have tests to run.
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

Re: TechDraw: export View to DXF

Post by easyw-fc »

wandererfan wrote: Mon Mar 19, 2018 12:03 pm As soon as I can figure out what form "__objs__" takes (OCC edge, FC edge, Draft wire, ...), I can build a version of FC where DrawViewPart has a method like "getEdges".
here a sample code to export a projection of shapes

Code: Select all

App.newDocument("Unnamed")
App.setActiveDocument("Unnamed")
App.ActiveDocument=App.getDocument("Unnamed")
Gui.ActiveDocument=Gui.getDocument("Unnamed")
App.ActiveDocument.addObject("Part::Torus","Torus")
App.ActiveDocument.ActiveObject.Label = "Torus"
App.ActiveDocument.recompute()
Gui.SendMsgToActiveView("ViewFit")
Gui.activeDocument().activeView().viewTop()
o = App.ActiveDocument.ActiveObject
vec = FreeCADGui.ActiveDocument.ActiveView.getViewDirection().negative()
import Draft
Draft.makeShape2DView(o,vec)
Gui.getDocument("Unnamed").getObject("Torus").Visibility=False
__objs__=[]
__objs__.append(FreeCAD.getDocument("Unnamed").getObject("Shape2DView"))
import importDXF
importDXF.export(__objs__,u"C:/Temp/Shape2DView.dxf")

del __objs__
Is this what you needed?
Please let me know if I may give more testing case

Code: Select all

App.newDocument("Unnamed")
App.setActiveDocument("Unnamed")
App.ActiveDocument=App.getDocument("Unnamed")
Gui.ActiveDocument=Gui.getDocument("Unnamed")
App.setActiveDocument("Unnamed")
App.ActiveDocument=App.getDocument("Unnamed")
Gui.ActiveDocument=Gui.getDocument("Unnamed")
App.ActiveDocument.addObject("Part::Torus","Torus")
App.ActiveDocument.ActiveObject.Label = "Torus"
App.ActiveDocument.recompute()
Gui.SendMsgToActiveView("ViewFit")
Gui.activeDocument().activeView().viewTop()
o = App.ActiveDocument.ActiveObject
vec = FreeCADGui.ActiveDocument.ActiveView.getViewDirection().negative()
import Draft
Draft.makeShape2DView(o,vec)
Draft.downgrade(FreeCADGui.Selection.getSelection(),delete=False)
FreeCAD.ActiveDocument.recompute()
__objs__=[]
__objs__.append(FreeCAD.getDocument("Unnamed").getObject("Edge"))
__objs__.append(FreeCAD.getDocument("Unnamed").getObject("Edge001"))
__objs__.append(FreeCAD.getDocument("Unnamed").getObject("Edge002"))
import importDXF
importDXF.export(__objs__,u"C:/Temp/edges.dxf")
#del __objs__
Gui.getDocument("Unnamed").getObject("Torus").Visibility=False
and this exporting edges
edges.FCStd
(6.26 KiB) Downloaded 52 times
wandererfan wrote: Mon Mar 19, 2018 12:03 pm But I don't think I can move it to master until 0.17 release shakes out.

I'll build it and act as your service bureau if you have tests to run.
If this would be just an enhancement with little additions, I think it could be added for this nice feature...
Post Reply