From observation, the workbenches found within either 'Mod' folder are loaded alphabetically.In the above example, you may place the 'MacroStartup' folder within the 'Mod' folder of your FreeCAD root directory (whether installed version or portable version), or you may create a 'Mod' folder along side the 'Macro' folder in '%USERPROFILE%\AppData\Roaming\FreeCAD\', and place the 'MacroStartup' folder there.This script will be run prior to the auto loading of your desired startup workbench in the FreeCAD Preferences, General settings.In the example 'InitGui.py' script above, the function named 'runStartupMacros()' may be changed, so long as you also change the other four references to it, so they all match.Notice that if the original macro was downloaded through the Addon Manager, it will be overwritten on update and thus you have to follow again the steps here. Your macro should automatically run at next FreeCAD launch. If you want to run more than one macro, you can just add the others in the same file (look at the comments on the above code). runStartupMacros = runStartupMacros # Connect the function that runs the macro to the appropriate signal FreeCADGui. So explicitly add it to _main_ import _main_ _main_. and the runMacro wouldn't be visible outside. if a second macro shall be launched at startup # import MyWonderfulMacro # n() # The following 2 lines are important because InitGui.py files are passed to the exec() function. disconnect ( runStartupMacros ) # Following 2 lines shall be duplicated for each macro to run import MySuperMacro MySuperMacro. Finally create in the same folder a file called 'InitGui.py' which contains the following code:ĭef runStartupMacros ( 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. Copy the modified macro into this newly created folder and rename it with a '.py' extension if this isn't yet the case (notice that if you develop the macro by yourself, it can be named with '.py' extension also in the 'Macro' folder so that you don't need to rename when copying). Now the macro is ready to be integrated in FreeCAD startup.įirst create a new folder in your user 'Mod' folder, let's say called 'MacroStartup'. Of course if the function 'run()' already exists in the macro, you can choose any other convenient name information ( None, "MyTitle", "MyText" ) # Enclose the main instructions in a function def run (): MyMsgBox () # Ensure main instructions are still called in case of manual run if _name_ = '_main_' : run () QMessageBox ): def _init_ ( self ): super ( MyMsgBox, self ). The original file shall be modified as follows:įrom PySide import QtGui # The 2 below lines shall be added if not already present to ensure FreeCAD modules are imported import FreeCAD as App import FreeCADGui as Gui class MyMsgBox ( QtGui. If you're not totally sure of what you're doing, it is advised to work on a copy of the macro (or you may just want to keep the original macro as is). run()- then ensure this function is still called when the macro is manually run by the user. To be able to do so, we need to enclose the main instructions in a function -eg. This can't be done with the actual structure of the macro. For later step, we'll need to programmatically import the macro then execute it. We will focus on this latter because main instructions (they are quite easy to spot because they start at the full beginning of the line) are actually the ones that 'execute' the macro. information ( None, "MyTitle", "MyText" ) # Main instruction section MyMsgBox ()Īll macros will generally present a similar structure with first import section, then definition section and finally main instruction section. # Import section # from PySide import QtGui # Definition section (classes, functions. Generally, it will happen that a macro isn't directly compatible with a startup launch and shall be fine-tunedĬonsider the below macro that you downloaded from somewhere and is stored in your 'Macro' folder with name 'MySuperMacro.FCMacro': This is rather appropriate for macros that add features, improve the UI.
0 Comments
Leave a Reply. |