View Issue Details

IDProjectCategoryView StatusLast Update
0003077TechDraw[FreeCAD] Featurepublic2018-11-09 00:24
Reportergntech Assigned To 
PrioritynormalSeverityminorReproducibilityN/A
Status acknowledgedResolutionopen 
PlatformLinuxOSUbuntu MateOS Version17.04
Product Version[FreeCAD] 0.17 
Target VersionFixed in Version 
Summary0003077: "Headless" export of SVG and PDF from TechDraw
DescriptionIt would be very beneficial to be able to export directly from the TechDraw module without running the GUI. This would allow for completely automated scripts to create a 3D-model generate a drawing and export as a SVG.

My particular usecase is that I design furniture that the customer can order to their exact dimensions. I therefor want to automate the process as much as possible. Right now I can create the 3d-model and TechDraw drawing directly from Python but the last step of actually exporting the SVG/PDF requires me to open the FreeCAD app and manually click export or running a macro from whitin the GUI.

See also https://forum.freecadweb.org/viewtopic.php?f=22&p=177330
Tagsheadless, python, SVG

Activities

gntech

2017-06-09 05:27

reporter   ~0009316

@ian.rees Your nickname was mentioned in the related forum thread as someone who has done some prior investigations on this or a similiar matter. Do you mind sharing your view on this request? It would be greatly appreciated :)

ian.rees

2017-06-11 19:19

developer   ~0009349

Hi gntech, sorry about the slow reply. The main issue in this area (at least as far as I remember) is that it's not possible to compile a useful TechDraw module without the Qt GUI module, at least with Qt4. The issue is to do with the QGraphics system - we have to use it, and also have to use QObject signals/slots/etc. I spent a few solid weeks of work on trying to concoct a workable solution and failed - if it's something you really want to try I can put together some notes and provide git branches from that effort.

All that said, I believe that the FreeCADCmd (headless) binary provides the same TechDraw scripting interface as FreeCAD (the normal GUI one), but don't have time to test at the moment. Our intent was to make the scripting interface at least as powerful as the original Drawing module, and from what I remember it is possible to script things like you describe.

Perhaps the missing bit of information from your thread, is just that you can run any old FreeCAD script directly from the command line ala
$FreeCADCmd some_script.FCMacro
. Does that help?

gntech

2017-06-27 05:12

reporter   ~0009556

Hi Ian, Thanks for your answer, but unfortunately it doesnt work even if I run the script via $FreeCADCmd.

It seems like the function I would like to use: App.ActiveDocument.exportPageAsSvg("filename.svg") is only available through TechDrawGui.

ian.rees

2017-06-27 05:16

developer   ~0009557

Hmm, sorry that it doesn't "just work".

Would you mind putting together a script that demonstrates what you're trying to do, which works in the GUI but not the CLI, and attaching it here? You've probably provided enough information above for me to put one together, but I'm really short on FreeCAD time lately and suspect you have already made something along those lines.

wandererfan

2017-06-29 00:34

manager   ~0009593

string = TechDraw.viewPartAsSvg(DrawViewPart) was added approx 2017-06-17. TechDraw API

This allows individual Views to be exported. At this time, there is no function to export a whole Page with Template and all its Views.

I don't see how PDF export will be possible without the Gui. On the App side, there is nothing to "print", just the raw data. On the Gui side we are actually printing a form of QWidget and Qt widgets just don't exist on the App side.

ian.rees

2017-06-29 20:54

developer   ~0009617

Hmm, I'm 90% sure that at some stage I had a scriptable interface to export a whole page just like if it were being printed - this was before my attempt to separate the UI from the QGraphics (so that it would be possible to compile a useful TechDraw without QtGUI). It's possible that got lost in the mix, I will try to make some time to look for it in the next couple weeks.

Isn't the Gui/App distinction is a compile-time one, but not a run time one? IE, we need the QtGUI module to use TechDraw, but I don't think that implies we need a GUI to use TechDraw.

wandererfan

2017-06-30 00:22

manager   ~0009619

IIRC App is not supposed to link to Gui in C++? But it is ok to load QtGui from Python?

My Python-fu is not strong. FreeCADCmd wouldn't let me import TechDrawGui or FreeCADGui so I couldn't use FreeCADGui.setupWithoutGUI().

It is probably possible to create MDIViews and QGraphicsViews without actually showing them, but I have no idea how to do it.

Would be great if you can find the script.

ian.rees

2017-07-01 03:58

developer   ~0009624

Aha, so the thing I was referring to did get lost in the mix. Have a look at https://github.com/ianrrees/FreeCAD_tinkering/commit/e5d2a127924f4c6720c6dab6172d7b1bdd79a5a1

Here's a relevant forum thread: https://forum.freecadweb.org/viewtopic.php?f=10&t=15835 .

Hopefully the situation is nicer with Qt 5; I have a vague memory of thinking it would be (and perhaps that's why it was dropped at the time?).

wandererfan

2017-07-01 14:58

manager   ~0009640

I'm going to consider the SVG part solved since it is possible to export a page as SVG with some additional Python.

As for PDF I'd say that's a "won't fix" for now, unless there's a way to convert edge geometry to PDF "code".

Kunda1

2017-07-03 11:38

administrator   ~0009652

@wandererfan did you benefit the code that ian shared with you?
Also in regards to 'a way to convert edge geometry to PDF "code"', should we post that question in the forums?

wandererfan

2017-07-03 15:35

manager   ~0009655

That code is from a previous design that didn't quite work out.

Looks like PDF uses PostScript internally so it should be possible to use similar strategy to viewPartAsPdf/viewPartAsDxf.

Kunda1

2017-07-03 17:41

administrator   ~0009657

@wandererfan should I open a separate ticket for the PDF portion of this ticket?

Kunda1

2017-07-11 20:04

administrator   ~0009717

@wandererfan ping

wandererfan

2017-07-12 16:17

manager   ~0009742

Unless you need an extra "tickets resolved" for the monthly stats, I'd just leave it. ;)

Kunda1

2017-07-12 16:38

administrator   ~0009743

@wandererfan actually I was going to decrease monthly stats based on my offer to open a new ticket 0003077:0009657

wandererfan

2017-11-25 01:32

manager   ~0010466

DXF not involved. Relationship to 2882 removed.

Kunda1

2018-11-07 00:47

administrator   ~0012141

@wandererfan question: Can i change the status away from 'feedback' ?

wandererfan

2018-11-07 13:28

manager   ~0012145

@Kunda1 - what do you want to change it to?

Kunda1

2018-11-07 13:31

administrator   ~0012147

@wandererfan acknowledged or assigned ?
(I'm cleaning out the 'feedback' tickets and was wondering if this was still in the 'feedback' stage.

wandererfan

2018-11-08 12:29

manager   ~0012151

Not "assigned", because it is too far down the prior list (like v0.25?).

Not sure what "acknowledged" means in the context of a feature request. "We acknowledge that you requested this feature"?

Maybe we need a "no now, but maybe someday" status? or "not on current roadmap"?

Kunda1

2018-11-09 00:24

administrator   ~0012156

Changing to 'acknowledged' and will figure out how to classify it later.
Thanks!

Issue History

Date Modified Username Field Change
2017-06-08 14:46 gntech New Issue
2017-06-09 03:04 Kunda1 Assigned To => ickby
2017-06-09 03:04 Kunda1 Status new => assigned
2017-06-09 03:05 Kunda1 Assigned To ickby =>
2017-06-09 03:06 Kunda1 Status assigned => acknowledged
2017-06-09 05:27 gntech Note Added: 0009316
2017-06-10 14:49 wandererfan Relationship added related to 0002882
2017-06-11 19:19 ian.rees Note Added: 0009349
2017-06-16 15:40 Kunda1 Tag Attached: python
2017-06-16 15:40 Kunda1 Tag Attached: headless
2017-06-16 15:41 Kunda1 Tag Attached: SVG
2017-06-21 10:59 Kunda1 Status acknowledged => feedback
2017-06-27 05:12 gntech Note Added: 0009556
2017-06-27 05:12 gntech Status feedback => new
2017-06-27 05:16 ian.rees Note Added: 0009557
2017-06-27 11:09 Kunda1 Status new => feedback
2017-06-29 00:34 wandererfan Note Added: 0009593
2017-06-29 20:54 ian.rees Note Added: 0009617
2017-06-30 00:22 wandererfan Note Added: 0009619
2017-07-01 03:58 ian.rees Note Added: 0009624
2017-07-01 14:58 wandererfan Note Added: 0009640
2017-07-03 11:38 Kunda1 Note Added: 0009652
2017-07-03 15:35 wandererfan Note Added: 0009655
2017-07-03 17:41 Kunda1 Note Added: 0009657
2017-07-11 20:04 Kunda1 Note Added: 0009717
2017-07-12 16:17 wandererfan Note Added: 0009742
2017-07-12 16:38 Kunda1 Note Added: 0009743
2017-11-25 01:31 wandererfan Relationship deleted related to 0002882
2017-11-25 01:32 wandererfan Note Added: 0010466
2018-11-07 00:47 Kunda1 Note Added: 0012141
2018-11-07 13:28 wandererfan Note Added: 0012145
2018-11-07 13:31 Kunda1 Note Added: 0012147
2018-11-08 12:29 wandererfan Note Added: 0012151
2018-11-09 00:24 Kunda1 Status feedback => acknowledged
2018-11-09 00:24 Kunda1 Note Added: 0012156