The main problem that I have is that since I'm just starting I make many mistakes. Also I do a lot of trial and error so I end up spending some time opening and closing Freecad. I know some things can be tested from the console but some others can not.
A little off topic, it would be great if the console would have command history.
Anyhow, I'll give you an example to see what I was doing:
In the Mod directory I have created a BoatDesign directory.
Inside that directory I have two files: BoatDesign.py and InitGui.py
InitGui.py
Code: Select all
class BoatWorkbench (Workbench):
MenuText = "Boat Design"
def Initialize(self):
import BoatDesign # assuming Scripts.py is your module
list = ["LoadHull","AddKeel","CalcDispl"] # That list must contain command names, that can be defined in BoatDesign.py
self.appendToolbar("Boat Design",list)
Gui.addWorkbench(BoatWorkbench())
BoatDesign.py
Code: Select all
import FreeCAD as App
import FreeCADGui as Gui
import Part
import FreeCAD.Base as Base
class LoadHull:
def Activated(self):
'''Loads a hull in any fo the formats supported by FreeCAD'''
if App.ActiveDocument is None:
App.Console.PrintMessage('Creating Document')
App.newDocument("Boat")
App.ActiveDocument=App.getDocument("Boat")
Gui.ActiveDocument=Gui.getDocument("Boat")
App.Console.PrintMessage('Select hull file')
Gui.runCommand("Std_Import")
Gui.runCommand("Std_FitAll")
hull = App.ActiveDocument.Objects[0]
hull.Label='Hull'
def GetResources(self):
return {'Pixmap' : 'path_to_an_icon/myicon.png', 'MenuText': 'Load Hull', 'ToolTip': 'Load a hull for the boat'}
Ok, that works but originally I have written App.activeDocument, wrong case. This is just an example, but the reload method did not work this time. What I did was:
import BoatDesign
reload(BoatDesign)
no errors but when I call the function again the syntax error is still there.