access to the methods of a python sketch

Having trouble installing or compiling FreeCAD? Get help here.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
damian
Posts: 583
Joined: Sun May 31, 2015 6:16 pm

access to the methods of a python sketch

Post by damian »

Good evening:
I've written a class for a python sketch, where I actually can obtain a signal of every change in the sketch's geometry through the execute() method.
Specifically my scripts knows and informs about if the sketch's geometry increase, decrease or still.
In the case of delGeometry I would like to capture the old numbering of the deleted edges, or the last selection before the cleaning.

Code: Select all

class _DynamoSketch():

    def __init__(self,sketch):
    	sketch.addProperty("Part::PropertyGeometryList","GeomHistory","Calenda")
    	sketch.Proxy = self
    	self.Type = "DynamoSketch"

    def execute(self,sketch):
    	geomHistory = sketch.GeomHistory ; oldLen = len(geomHistory)
    	geometryList = sketch.Geometry ; newLen = len(geometryList)
    	
    	if oldLen == newLen:
    		print 'equal'
    	elif oldLen > newLen:
    		print 'down'
    		# I would like to obtain the numeration of the removed edges
    	elif oldLen < newLen:
    		print 'up'
    	
    	sketch.GeomHistory = geometryList
    	
    	sketch.recompute()
	

class _ViewProvider_DynamoSketch():

    def __init__(self,vobj):
        vobj.Proxy = self
	
    def getIcon(self):
        return iconPath() + "calenda.svg"

    def getDefaultDisplayMode(self):
        return "Wireframe"


dynamoSketch = FreeCAD.ActiveDocument.addObject("Sketcher::SketchObjecPython","DynamoSketch")
_DynamoSketch(dynamoSketch)
_ViewProvider_DynamoSketch(dynamoSketch.ViewObject)
For instance, the python console could print something like this

Code: Select all

App.ActiveDocument.Sketch.delGeometry(2)
And my script must know that the removed topo is 'Edge3'
has anybody an idea?
Thank you

Edit: I confuse the forum. This question is for python scripting and macros
Post Reply