View Issue Details

IDProjectCategoryView StatusLast Update
0003351TechDrawBugpublic2018-10-25 13:49
ReporterJMG Assigned Towandererfan  
PrioritynormalSeveritycrashReproducibilityalways
Status closedResolutionunable to reproduce 
Product Version0.17 
Target Version0.18Fixed in Version0.18 
Summary0003351: Automated part to techdraw drawing script (python) crashes freecad at completition
DescriptionA python script that automatically draws a tech-draw drawing for each part in document makes freecad crash every time.
Steps To ReproduceThis script generates some random boxes and then generates a tech-draw page and view for each one of them, modifying some parameters like direction of projection and some fields of the template (part name and some specifications, just text)

Run by copy-paste on python terminal inside freecad:

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)


Additional InformationForum thread: https://forum.freecadweb.org/viewtopic.php?f=35&t=26991

My setup info:
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)


Crash reproduced in this machine too:
OS: Ubuntu 16.04.3 LTS
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: English/Canada (en_CA)

TagsNo tags attached.
FreeCAD Information

Activities

wandererfan

2018-10-25 13:46

manager   ~0012091

This problem seems to have been fixed. I can run the script up to 75 pages without a crash on FC daily without a crash. The last ten pages are definitely slower to build than the first 10, but it doesn't crash.

I'm going to close this issue. We can reopen the ticket if the problem shows up again.

OS: Linux Mint 18.3 Sylvia
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15007 (Git)
Build type: Release
Branch: master
Hash: 70fef3934190aabc61f5e1346483359d5ad21403
Python version: 2.7.12
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/Canada (en_CA)
NoCrash75vDaily.fcstd (277,495 bytes)

wandererfan

2018-10-25 13:49

manager   ~0012092

No longer reproducible.

Issue History

Date Modified Username Field Change
2018-02-22 08:46 JMG New Issue
2018-05-30 15:51 Kunda1 Target Version => 0.18
2018-10-25 13:46 wandererfan File Added: NoCrash75vDaily.fcstd
2018-10-25 13:46 wandererfan Note Added: 0012091
2018-10-25 13:47 wandererfan Status new => resolved
2018-10-25 13:47 wandererfan Resolution open => unable to reproduce
2018-10-25 13:47 wandererfan Fixed in Version => 0.18
2018-10-25 13:49 wandererfan Assigned To => wandererfan
2018-10-25 13:49 wandererfan Status resolved => closed
2018-10-25 13:49 wandererfan Note Added: 0012092