Create a FreeCAD Workbench – Command Code

This article will be referring to the code run from the Command Class as the “Command Code.”

I the code included, the execute command adds a simple shape to the Object we created with Sample_Command

Here is our “Sample”Command Code class

class Sample:

	def __init__(self, obj):

		print ("The sample class has been instantiated init")
		obj.addProperty("App::PropertyFloat","MyPropertyName","MyPropertyCategory","A short description").MyPropertyName = 10
		obj.Proxy = self

	def onChanged(self, fp, prop):
		''' Do something here '''
		FreeCAD.Console.PrintMessage("Changed property:\n") 
	
	def execute(self,fp):
		print ("Sample Class executed()")
		dimemsion = fp.getPropertyByName("MyPropertyName")
		fp.Shape = Part.makeBox( dimemsion,dimemsion,dimemsion )
		fp.ViewObject.Proxy=0

fp an object passed in by the Workbench. Think of it as “freecad part”. It is a reference to the oobject added when we added “newPart”. So the operations are at the same level. The fp object itself is the container and it’s child Shape contains the geometry.


Leave a Reply