Launching Macro File Creation

Hello everyone!

Would someone tell me if one can run a macro when creating a document (room, plan, set) via a document template?
To make it clearer, I'd like that when I create a drawing via a specific drawing template it starts the macro!

Do you have an idea?

Thanks in advance! :slight_smile:

2 Likes

Hello
You need to use SW events (this code for example: Fire Application and Document Events Example (VBA) - 2021 - SOLIDWORKS API Help
On the other hand, you have to modify the exe launching SW to load the macro that will run in the background (code it well to avoid client crashes)

2 Likes

Is there no other way without modifying the exe?

To my knowledge, not to have a module that runs in the background and runs according to what the user does.
After that, there are the macro features but hey, it's related to the personal file, I'm not a fan.

2 Likes

I'll look into it... :slight_smile:

Hello
@Cyril.f And with a command-line addition of the launcher shortcut?
I don't know if a command exists for that.

EDIT: Apparently yes, it's /m "C:\myMacro.swp" to add behind the path in the properties of the solidworks shortcut.

That's right

What can be tempted if you are aiming for a specific file/doc rather than a systematic launch, is to create a shortcut to this file, to add the above-mentioned command to this shortcut rather than to the SW one. The file can be a blank file starting from the targeted template and saved in sdldrw format.
Hopefully, solidworks will execute the command after opening the file.
If it works, then just open an mep from the shortcut rather than from SW.
Just an idea like that.

1 Like

I'm interested in this avenue! I'll try to dig into this when I have some time :slight_smile:
Thank you very much

Hello

If it's too complicated to do it in this direction, you may have to see if it's not easier to do it the other way around, so launch your macro which starts by creating the drawing for you.
Kind regards

3 Likes

Yes, not wrong! But we have several document templates and I wanted the way to create an outline to be "homogeneous" :slight_smile: That's why I would have liked to be able to run a macro when creating a specific doc template! Because it's not easy to make everyone understand that to create this type of plan you have to go through one place and for other types launch the macro etc ...

In this case, why not launch a macro with a menu to choose the type of plan or, if possible, according to a property, it directs you to the right type of MEP
Like my colleagues, it is much simpler in this sense

3 Likes

It's true that it would be simpler and more practical! I hadn't even thought about it :smiley:

Hello.
I prefer the use of a Macro button rather than an auto-launch macro.

Hello
However, users must be willing to launch it. It's a bit of a problem not to do it in the background, it's up to each person's judgment and depending on the number of users and potential refractories you can end up with files that don't conform to the expected.