1

Note - I'm not running a script in the python console inside FreeCAD. This is all in a python script in a docker container with FreeCAD installed.

I'm trying to make an SVG of a page generated by FreeCAD running in a python script. I have views of a shape no problem, but cannot figure out how to add dimensions AND save to an SVG. There are a couple options that get close as far as I can tell...

  1. Using the older Drawing module (and drawing_dimensioning):

I can make an SVG of a page with views of my shape, but cannot add dimensions. The module drawing_dimensioning is perfect if I was using full GUI FreeCAD. I cannot seem to use this module from the python script however. When I import it, I get the following error:

  File "/usr/lib/freecad/Mod/drawingDimensioning/core.py", line 184, in <module>
FreeCADGui.addCommand('dd_help', helpCommand())
AttributeError: 'module' object has no attribute 'addCommand'

I've tried many of the fixes for this error, but cannot find any solutions that work. Does this have something to do with drawingDimensioning having FreeCADGui as a dependency? is FreeCADGui missing addCommand()? If you know of another approach, please comment.

  1. The newer TechDraw module:

As far as I can tell this works (although with fewer features than drawing_dimensioning). BUT I cannot use the module TechDrawGui from the command line. The TechDrawGui module is required for saving a TechDraw page to SVG. I get this error when I do:

  File "/app/main_process.py", line 14, in <module>
import Part, Drawing, FreeCADGui, TechDrawGui
ImportError: Cannot load Gui module in console application.

I CAN however import FreeCADGui module without any problems. Importing and Using the TechDraw module seems fine too.

Thanks for reading. If you think you have a method of creating dimensions on a page and saving as SVG all from python, please let me know!

Richard
  • 336
  • 4
  • 12

1 Answers1

1

Yes, you are right. While running FreeCAD inside docker container (or compiled without GUI), then many features of workbenches that requires GUI for there execution will be unavailable. However, you can fix them by dig into FreeCAD codebase, create an issue at https://www.freecadweb.org/tracker/my_view_page.php or solve your problem by using the core functionality of FreeCAD.

Regarding your problem, I have a solution: https://gist.github.com/amrit3701/8f67c8ea06c74a64bca08a0a48560556

The above example creates an SVG file of a cube with its dimensions. For creating dimensions, I used Draft.makeDimension function and for producing view (SVG content) of a Part object (i.e. Cube), I used Drawing::FeatureViewPart object.

Output SVG file after running main.py in the above-mentioned link ouput.svg

Amritpal Singh
  • 4,496
  • 1
  • 10
  • 7