AnsweredAssumed Answered

Inherit or call from common macros file

Question asked by Jeff Fleckenstein on Jan 31, 2018
Latest reply on Jan 31, 2018 by Jeff Fleckenstein

I am finding that I am using similar functions (either Solidworks related or file maintenance stuff) in numerous macros and I have been copying them from one to the next. Every once in a while, I find a reason to change said function, but I usually do not desire to find and update everything I've copied it into. So, I would like to place all of my functions into one common file.


So I attempted to create an otherwise arbitrary .swp file that includes a collection of my common functions. Using the .RunMacro2 method, this works just fine for any standalone subs that do not require passing any variables to or from. This is what I tried:

Debug.Print swApp.RunMacro2(MyFullMacroPath, MyModuleName,MyFunctionName,swRunMacroUnloadAfterRun,MyMacroError)

Where MyFunctionName is something like "SaveAsPDF(swDoc,SaveAsPath)"


Is there a method that I am missing where I can call a macro from a separate file while sending or returning variables?


Note: I have used inheritance on projects outside of Solidworks and I feel like I might be able to make a class that inherits my common functions. However, I would need to know how to reference from an external file.


Note2: For my example above, I could probably make it work by assuming the active solidworks document as my swDoc and then prompting the user for a SaveAsPath. However, I have numerous functions that do very specific things and require variables to be sent or returned. (Honestly, I feel like I am unnecessarily dreaming a bit here. But if I didn't ask...)