Macro Document Template

Hello

In my company, we have a document template for parts files.

I'd like to incorporate a macro into this model. The goal is for everyone using the model to have access to the macro.

I have not found a solution to do this. Do you know if there is anything or if each person will have to add a new button with the link to the macro?

Thank you

Hello

What is the purpose of this macro??? You may be able to add it as a note in your template.

It is a macro that creates a sketch at the center of gravity (we use Solidworks 2012).

If I add it as a note in my template, I can put the link to the macro but I don't know how to launch it. Also, if I add a note, every time I turn the view, the annotation disappears.

Ideally, if a user opens the document template, then a button appears to launch the macro without the need to manually add the button with the link to the macro first.

We create the center of mass when the part is finished, because if you create the sketch according to the center of mass it will no longer be just if you add a hole or a tab and or a fold...

Here is the macro center of mass:

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = _
Application.SldWorks

Set Part = swApp.ActiveDoc
Dim CenterOfMass As Object
Set CenterOfMass = Part.FeatureManager.InsertCenterOfMass()
End Sub


centre_der_masse.jpg
1 Like

Hello

No, it is not possible to my knowledge to add a macro button in a document template.

We could use the same settings for everyone with the wizard to copy the settings, taking care to integrate the macro button before, so everyone has this button:

http://help.solidworks.com/2012/French/SolidWorks/sldworks/Copy_Options_Wizard.htm

 

2 Likes

It is possible to create a button in a room. But you have to create the macro in excel with a button and then you go to the room and do:

insert==>object==>create from a file and there  you select your file with the button.

Once the file is in the room, you will have to double click on it, then the button will be accessible to launch it...


bouton_ou_case.jpg

Why a macro in the model? I think like @PL that it's not possible.

Otherwise, can't this Macro work from a button created for this purpose put in the menus?

Hi all

Thank you for your answers.

@ac cobra 427, with the macro I downloaded I can insert the center of gravity at any time since it updates every time the part or assembly changes. On the other hand, the code is much longer and more complicated than the one you propose in your answer. So I'll see to use yours but as I understand it it only takes into account the parts and not the assemblies, right?

Edit: the code doesn't work, it crashes on the line Set CenterOfMass = Part.FeatureManager.InsertCenterOfMass()

Another question, how do you insert it into the "Reference Geometry" menu?

Regarding the idea of creating the macro in Excel and then importing it, it's good but I think users prefer to have a "classic" button.

 

@.PL, that's what I thought but I asked the question to confirm. For the settings, we (normally) already have all the same, so everyone will have to add the button to their menu.

 

@alain. ERP, the purpose of integrating the macro into the model is to avoid that every user needs to add the button to the menu but I think that's what we're going to do in the end. When you talk about a button in the menus, it is possible to choose where the button will be or will it necessarily be in the taskbar?

 

Have a nice day.

1 Like

In fact the code comes from the macro recorder, I started the recording and did the manipulation by creating the center of mass then I stopped it and that's the code I got....

If I helped, thank you for marking my answer as the best.