ich habe versucht, nach dieser Anleitung ein Makro automatisch ausführen zu lassen. Leider gelingt mir dies nicht und FC zeigt mir beim starten im Ausgabefenster folgenden Fehler:
Code: Select all
12:53:30 During initialization the error "name 'runMacro' is not defined" occurred in /home/rga/.FreeCAD/Mod/MacroAutoStart/InitGui.py
12:53:30 Please look into the log file for further information
Code: Select all
import FreeCAD as App
import FreeCADGui as Gui
class DocObserver():
def slotCreatedDocument(self,doc):
print ("Dokument erstellt")
def slotDeletedDocument(self,doc):
self.cancelObservation(obs)
print ("Dokument gelöscht")
def slotChangedObject(self,doc,obj):
print("Du hast ein Objekt verändert!")
def slotRecomputedObject(self,doc):
print("Aktualisierung ausgelöst")
def slotCreatedObject(self,doc):
print("Ein neues Objekt hinzugefügt")
def cancelObservation(self,obs):
App.removeDocumentObserver(obs)
print("Überwachung abgebrochen")
# function to detect work bench change
def wbChange(name):
print ("Du hast folgende Workbench aktiviert: {}".format(name))
# set up document observer
def run():
obs=DocObserver()
App.addDocumentObserver(obs)
##Ensure main instructions are still called in case of manal run
if __name__ == '__main__':
run()
# initiate a new doc
#doc = FreeCAD.newDocument()
#mw=Gui.getMainWindow()
#mw.workbenchActivated.connect(wbChange)
# Do something:
#Volume = doc.addObject("Part::Sphere", "TreatmentVolume")
# recompute:
#doc.recompute()
#Gui.SendMsgToActiveView("ViewFit")
#Gui.activateWorkbench("PartWorkbench")
# now play with the object size etc, and note the resultant messages in the Report View
Code: Select all
def runMacroStartup(name):
#Do not run when NoneWorkbench is activated because UI isn't yet completely there
if name != "NoneWorkbench":
#Run macro only once by disconnecting the signal at first call
FreeCADGui.getMainWindow().workbenchActivated.disconnect(runMacroStartup)
##Following 2 lines shall be duplicated for each macro to run
import DocObserver
DocObserver.run()
##Eg. if a second macro shall be launched at startup
#import MyWonderfulMacro
#MyWonderfulMacro.run()
##The following 2 lines are important because InitGui.py files are passed to the exec() function...
##...and the runMacro wouldn't be visible outside. So explicitly add it to __main__
import __main__
__main__.runMacro = runMacro
##Connect the function that runs the macro to the appropriate signal
FreeCADGui.getMainWindow().workbenchActivated.connect(runMacro)
Roli