7erra 629 Posted October 15, 2021 CfgFunctions Generator This is a little Python script I wrote to generate a CfgFunctions.hpp file which can be included in the main config (either description.ext or config.cpp). This script assumes the following project structure: A functions folder in the mission/mod directory The python script resides in the "functions" folder Subfolders with the name of the category Function files in those category folders Function files start with "fn_" Here is an example: Folder structure mission.vr/ ├─ description.ext ├─ functions/ │ ├─ Category1/ │ │ ├─ fn_myFunction.sqf │ ├─ Category2/ │ │ ├─ fn_anotherFunction.sqf │ │ ├─ fn_aFunction.sqf │ ├─ generate.py │ ├─ CfgFunctions.hpp Output (in CfgFunctions.hpp): #ifdef DEBUG_ENABLED_FULL allowFunctionsRecompile = 1; allowFunctionsLog = 1; #endif class CfgFunctions { class MIS { class Category1 { class myFunction; }; class Category2 { class aFunction; class anotherFunction; }; }; }; A new file called "CfgFunctions.hpp" will be created in the "functions" folder. It can be added to the config by adding the following line to your description.ext/config.cpp: #include "functions\CfgFunctions.hpp" Installation Install Python Create a new file called "generate.py" in your functions directory Paste the code from below into the file Usage Change the line "tag = 'MIS'" to your tag (only needed to be done once) Open a command-line in the functions directory Execute python3 "generate.py" License MIT generate.py from pathlib import Path tag = 'MIS' folder_functions = Path(__file__).parent.resolve() file_cfg = folder_functions / 'CfgFunctions.hpp' content = [ "#ifdef DEBUG_ENABLED_FULL", "allowFunctionsRecompile = 1;", "allowFunctionsLog = 1;", "#endif", "class CfgFunctions", "{", f"\tclass {tag}", "\t{" ] # Get all categories by looking at the folders categories = [x for x in folder_functions.iterdir() if x.is_dir()] categories.sort(key=lambda x: x.name.upper()) for cat in categories: content.extend([f'\t\tclass {cat.name}', "\t\t{"]) # Get all functions from the files function_files = [f.stem.replace('fn_', '') for f in cat.iterdir() if f.is_file() and f.name.startswith('fn_')] function_files.sort(key=lambda x: x.upper()) for f in function_files: content.append(f'\t\t\tclass {f};') content.append('\t\t};') content.extend(["\t};","};"]) output = '\n'.join(content) file_cfg.write_text(output) 1 Share this post Link to post Share on other sites