Word size of OS: 32-bit
Word size of FreeCAD: 32-bit
Version: 0.18.15353 (Git)
Build type: Release
Branch: master
Hash: 20fe774784bd013c74c1edaed8985e851bb1370b
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
Hello all,
I am attempting to add some sketches, that I create over and over, into a workbench. I am also trying to learn to code Python and implement Workbenches. I have the following command as an example. Mostly I have just followed examples and hacked my way through so far. I have included a test command demonstrating my approach. The shapes in the long run will be more complicated.
My problem is that when I click the command button it creates a sketch with two lines as expected. However, if I delete a line the execute() method gets called and adds two additional lines. So I am not sure where I should put the sketch code or more importantly why the execute() is getting called. I have used this approach for Part::FeaturePython objects and it seems to work fine, but clearly I am not fully understanding the execute() method.
I did look around in forums for awhile but I don't even really know what I am looking for.
Thank you so much in advance.
Code: Select all
import FreeCAD,FreeCADGui,Part, Sketcher
import os
class MyLine_Command:
def GetResources(self):
return {"MenuText": "MyLine",
"ToolTip": "Tooltip for MyLine command" }
def IsActive(self):
if FreeCAD.ActiveDocument == None:
return False
else:
return True
def Activated(self):
c=FreeCAD.ActiveDocument.addObject('Sketcher::SketchObjectPython','MyLine')
print "Sketcher Object TyepID: " + c.TypeId
sketcherObject = MyLine(c)
c.ViewObject.Proxy=0
#FreeCAD.ActiveDocument.recompute()
class MyLine:
def __init__(self, obj):
obj.Proxy = self
def onChanged(self, fp, prop):
name = str(prop)
newvalue = str(fp.getPropertyByName(str(prop)))
def execute(self,fp):
geometryList = []
geometryList.append( Part.LineSegment(FreeCAD.Vector(-44.546316,-2.496507,0),FreeCAD.Vector(44.830833,-2.496507,0)))
geometryList.append( Part.LineSegment(FreeCAD.Vector(-44.546316,2.503493,0),FreeCAD.Vector(44.544970,2.503493,0)))
fp.addGeometry( geometryList, False)
fp.recompute()
FreeCADGui.addCommand('MyLine', MyLine_Command())