Thanks to all of three for the answers!
I am trying the code above but I still have a strange behavior: the application is apparently blocked (the window does not respond) and after a while (a few minutes) the following error appears:
Code: Select all
<unknown exception traceback><type 'exceptions.RuntimeError'>: maximum recursion depth exceeded
Traceback (most recent call last):
File "C:\Program Files\FreeCAD_0.14.2778_x64\Mod\myMod\MyTools.py", line 46, in execute
text_tmp = Draft.makeShapeString(self.label,"../Mod/myMod/fonts/Arial.ttf", 3., 0) # a document object
File "C:\Program Files\FreeCAD_0.14.2778_x64\Mod\Draft\Draft.py", line 1985, in makeShapeString
_ShapeString(obj)
File "C:\Program Files\FreeCAD_0.14.2778_x64\Mod\Draft\Draft.py", line 4220, in __init__
_DraftObject.__init__(self,obj,"ShapeString")
<type 'exceptions.RuntimeError'>: maximum recursion depth exceeded while calling a Python object
T1: maximum recursion depth exceeded while calling a Python object
If I start FreeCAD and run the commands in the Python console they seem to work fine.
But, if I start FreeCAD, execute my Tool, wait the function to return with the error and finally run the commands in the Python console the application blocks again.
This is the code in the execute function:
Code: Select all
def execute(self, fp):
''' Draw a line to highlight the edge with a label'''
line = Part.makeLine(fp.P1, fp.P2) # a shape
text_tmp = Draft.makeShapeString(self.label,"../Mod/MPH/fonts/Arial.ttf", 3., 0) # a document object
ts = text_tmp.Shape.copy() # a shape
App.ActiveDocument.removeObject(text_tmp.Name)
tsplm = ts.Placement
tsplm.move(line.BoundBox.Center)
compshape = Part.Compound([line, ts]) # a shape
# Part.show(compshape)
fp.Shape = Part.Compound([line, ts])
I guess something is wrong with Draft.makeShapeString but I can't understand what it is.
I have updated to the following version:
Code: Select all
OS: Windows 7
Platform: 64-bit
Version: 0.14.2778 (Git)
Branch: master
Hash: 0506a918b24e015ac6277a7cf613ce151e1dee44
Python version: 2.6.4
Qt version: 4.5.3
Coin version: 2.4.5a
SoQt version: 1.4.1