I am working on an automated part to tech-draw drawing script and it crashes FreeCAD every time I run it.
This is the python code:
Code: Select all
import time
import FreeCADGui
from operator import itemgetter
import random
base_name = "EDCPI_"
drawing_revision = 'R0'
author_name = "JMG"
max_label = 50
current_label = 0
# create new document
FreeCAD.newDocument("Unnamed")
FreeCAD.setActiveDocument("Unnamed")
FreeCAD.ActiveDocument=App.getDocument("Unnamed")
FreeCAD.Gui.ActiveDocument=Gui.getDocument("Unnamed")
# create dummy objects
for i in range(max_label):
obj = FreeCAD.ActiveDocument.addObject("Part::Feature", base_name + str(current_label))
obj.Shape = Part.makeBox(random.randint(5,30),random.randint(5,30),random.randint(5,30) )
obj.Placement.Base.x = random.randint( -100, 100 )
obj.Placement.Base.y = random.randint( -100, 100 )
obj.Placement.Base.z = random.randint( -100, 100 )
current_label += 1
current_label = 0
def doDrawingForLabel(label):
current_label = label
for obj in FreeCAD.ActiveDocument.Objects:
try:
if int( obj.Label[len(base_name):] ) == current_label:
if obj.Shape.Volume != 0: #check for solid
# create and setup page
draw_page = FreeCAD.ActiveDocument.addObject("TechDraw::DrawPage", obj.Label )
# TODO TEMPLATE IN DEPENDENCE OF BOUND BOX
# adjust templat
template = FreeCAD.ActiveDocument.addObject( 'TechDraw::DrawSVGTemplate', 'Template')
template.Template = "/usr/share/freecad-daily/Mod/TechDraw/Templates/A3_Landscape_ISO7200TD.svg"
draw_page.Template = template
# fill template
date = time.localtime()
template.setEditFieldContent("FC-DATE", str(date.tm_mday) + '/' + str( date.tm_mon ) + '/' + str( date.tm_year ) )
template.setEditFieldContent("DRAWING_TITLE", obj.Label )
template.setEditFieldContent("AUTHOR_NAME", author_name )
template.setEditFieldContent("FC-SC", "1:1")
template.setEditFieldContent("PN", obj.Label )
template.setEditFieldContent("FC-SH", str(current_label ) + " / " + str(max_label - 1 ) )
template.setEditFieldContent("FC-REV", drawing_revision )
# number of equal parts
part_counter = -1
for p in FreeCAD.ActiveDocument.Objects:
if p.Label == obj.Label:
part_counter +=1
template.setEditFieldContent("SI-4", str(part_counter) + " unidades" )
# set selection here
FreeCAD.Gui.Selection.clearSelection()
FreeCAD.Gui.Selection.addSelection(draw_page)
FreeCAD.Gui.Selection.addSelection(obj)
# create view
part_view = FreeCAD.ActiveDocument.addObject( 'TechDraw::DrawViewPart', obj.Label + "_view" )
draw_page.addView(part_view)
part_view.Source = [obj]
# check viewpoint refered
bbox_bounds = obj.Shape.BoundBox.XLength, obj.Shape.BoundBox.YLength, obj.Shape.BoundBox.ZLength
min_idx = min( enumerate(bbox_bounds), key=itemgetter(1))[0]
# add sheet dimension to data template
template.setEditFieldContent("FreeCAD_DRAWING", "Chapa de " + str( round(bbox_bounds[min_idx]) ) + "mm en Acero St 37" )
view_direction = FreeCAD.Vector(0.0,0.0,0.0)
view_direction[min_idx] = 1.0
part_view.Direction = view_direction
FreeCAD.ActiveDocument.recompute()
current_label += 1
break
except ValueError:
print obj.Label
for i in range(max_label):
doDrawingForLabel(i)
The trace FreeCAD leaves on terminal is:
Code: Select all
FreeCAD 0.17, Libs: 0.17R13303 (Git)
© Juergen Riegel, Werner Mayer, Yorik van Havre 2001-2018
##### #### ### ####
# # # # # #
# ## #### #### # # # # #
#### # # # # # # # ##### # #
# # #### #### # # # # #
# # # # # # # # # ## ## ##
# # #### #### ### # # #### ## ## ##
Fasteners workbench Loaded
During initialization the error "'Tubos' already exists." occurred in /home/javier/.FreeCAD/Mod/TubosWorkbench/InitGui.py
Please look into the log file for further information
not a freecad file: .STEP
not a freecad file: .STL
Program received signal SIGSEGV, Segmentation fault.
#0 /lib/x86_64-linux-gnu/libc.so.6(+0x354b0) [0x7f3d636e84b0]
#1 /lib/x86_64-linux-gnu/libc.so.6(strlen+0x26) [0x7f3d6373e746]
#2 0x7f3d5e84ffc3 in Shiboken::setErrorAboutWrongArguments(_object*, char const*, char const**) from /usr/lib/x86_64-linux-gnu/libshiboken-python2.7.so.1.2+0x6c3
#3 /usr/lib/python2.7/dist-packages/PySide/QtCore.so(+0x117cb9) [0x7f3d3a480cb9]
#4 /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x8ad0) [0x7f3d652ae9f0]
#5 /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x85c) [0x7f3d653e405c]
#6 /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(+0x13e370) [0x7f3d6533a370]
#7 /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyObject_Call+0x43) [0x7f3d6530d273]
#8 /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyEval_CallObjectWithKeywords+0x47) [0x7f3d653e3487]
#9 0x7f3d3a103d99 in PySide::SignalManager::callPythonMetaMethod(QMetaMethod const&, void**, _object*, bool) from /usr/lib/x86_64-linux-gnu/libpyside-python2.7.so.1.2+0x79
#10 /usr/lib/x86_64-linux-gnu/libpyside-python2.7.so.1.2(+0x16459) [0x7f3d3a10b459]
#11 0x7f3d641b4166 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) from /usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x626
#12 /usr/lib/python2.7/dist-packages/PySide/QtCore.so(+0x1a16e3) [0x7f3d3a50a6e3]
#13 0x7f3d641b9c83 in QObject::event(QEvent*) from /usr/lib/x86_64-linux-gnu/libQtCore.so.4+0xa3
#14 /usr/lib/python2.7/dist-packages/PySide/QtCore.so(+0x1a1263) [0x7f3d3a50a263]
#15 0x7f3d646ccfdc in QApplicationPrivate::notify_helper(QObject*, QEvent*) from /usr/lib/x86_64-linux-gnu/libQtGui.so.4+0x8c
#16 0x7f3d646d3f16 in QApplication::notify(QObject*, QEvent*) from /usr/lib/x86_64-linux-gnu/libQtGui.so.4+0x2b6
#17 0x7f3d66332d94 in Gui::GUIApplication::notify(QObject*, QEvent*) from /usr/lib/freecad-daily/lib/libFreeCADGui.so+0x54
#18 0x7f3d6419f90d in QCoreApplication::notifyInternal(QObject*, QEvent*) from /usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x8d
#19 /usr/lib/x86_64-linux-gnu/libQtCore.so.4(+0x1bd780) [0x7f3d641d2780]
#20 /usr/lib/x86_64-linux-gnu/libQtCore.so.4(+0x1ba8f1) [0x7f3d641cf8f1]
#21 /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_dispatch+0x2a7) [0x7f3d5cdd7197]
#22 /lib/x86_64-linux-gnu/libglib-2.0.so.0(+0x4a3f0) [0x7f3d5cdd73f0]
#23 /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_iteration+0x2c) [0x7f3d5cdd749c]
#24 0x7f3d641d02ae in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) from /usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x7e
#25 /usr/lib/x86_64-linux-gnu/libQtGui.so.4(+0x272616) [0x7f3d6477a616]
#26 0x7f3d6419e18f in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) from /usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x3f
#27 0x7f3d6419e4f5 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) from /usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x1b5
#28 0x7f3d641a44b9 in QCoreApplication::exec() from /usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x99
#29 0x7f3d662ebb70 in Gui::Application::runApplication() from /usr/lib/freecad-daily/lib/libFreeCADGui.so+0x15b0
#30 freecad-daily(main+0x8b4) [0x403834]
#31 /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f3d636d3830]
#32 freecad-daily(_start+0x29) [0x404a79]
If someone else can confirm this crash I'll post it to mantis.OS: Linux Mint 18 Sarah
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13303 (Git)
Build type: None
Branch: master
Hash: b47e011c1cc6357fa776624d371ed434989c79b1
Python version: 2.7.12
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.1.0
Locale: Spanish/Spain (es_ES)
(I placed the post here because tech-draw is the module involved, feel free to move this where it suits better)
Regards,
Javier.