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
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:
@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?
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....