Error on "Run macro at start up"

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Error on "Run macro at start up"

Post by freedman »

I get this report error: Also shows the version I'm running.

Code: Select all

During initialization the error "name 'Toggle1_1' is not defined" occurred in C:\Current FreeCAD\FreeCAD_weekly-builds-24910-Win-Conda_vc14.x-x86_64\Mod\MacroStartup\InitGui.py


I have my macro "Toggle1_1.py" in the MacroStartup folder and the added "run()" statement is in it, just like what the directions said. Here is a listing of the InitGui but It's not very clear in the instructions what should be put in the "Important" section at the bottom, this is what I did:

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 Toggle1_1
        Toggle1_1.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 = Toggle1_1

##Connect the function that runs the macro to the appropriate signal
FreeCADGui.getMainWindow().workbenchActivated.connect(Toggle1_1)
Any ideas what I messed up? Maybe someone could post their InitGui.py file.
Thanks
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Error on "Run macro at start up"

Post by freedman »

I went back and started over. I put the two commands in my macro. I reloaded the default InitGui.py file in my my mod/macrostartup folder. I then renamed my macro "MySuperMacro" so there wouldn't be any confusion. It still doesn't work and I get this error:

Code: Select all

During initialization the error "name 'runMacro' is not defined" occurred in C:\Current FreeCAD\FreeCAD_weekly-builds-24910-Win-Conda_vc14.x-x86_64\Mod\MacroStartup\InitGui.py
It does seem to get loaded but it does not run. Once FreeCAD is open if I try to start the macro locally I get a message that it's already running (and my local copy exits on a exception, then the macro starts working.
Help!
Post Reply