New Button for New Macro

Is there a way to programatically create a new button on themacro toolbar using VBA?

I am looking for a way that my users can just run a quick marco and*.reg file to add a button to their macro toolbar and set it to usea newly created macro. I don't want to have to keep going from PCto PC to setup a new toolbutton everytime I create a new macro.

Any other ideas are welcome...SolidworksApi macros
Answers 10
JB
JB 2009-05-04 Best Answer
Dan

(I had some problems with the formatting of this post - I thereforerepost it)

I haven't investigated if it can be done by means of VBA but Irecently had the same need and I found a method. It's simple anddirty but it works. The only downside is that the entire Macrotoolbar setup is distributed to the users so any changes made bythe users to their own macro toolbar will be overwritten.

- Locate the macro in a common network folder
- Setup the macro button to the macro toolbar on your PC includinga 16x16 pixel button image
- Use SW Copy Settings Wizard to save SW settings to a file -include Macro toolbar only
- Create a folder called "MacroToolbar" somewhere on your harddrive- for example in My Documents
- Add the SW registry file and the button image file to the folder
- Create a new text file called SWMacroToolbar.bat file in thefolder
- Add the following to the bat-file:

copy /Y "%CD%\ButtonImageFileName.bmp" "C:\Program Files\SolidWorks2009\SolidWorks\data\user macro icons\"
"%CD%\SWRegistryFileName.reg"

- Replace "ButtonImageFileName" and "SWRegistryFileName" with yourown file names. Adjust the path to the SolidWorks installationfolder if needed.

- If you prefer to copy the macro files to the users local harddrive instead of referencing them on a netwotk drive then simplyadd the macro file to the folder and add another line to thebat-file:

copy /Y "%CD%\MacroFileName.swp" "C:\Program Files\SolidWorks2009\SolidWorks\Macros\"

- If the macro folder is not already made you will have to createit with the "md" command. Add the following to the bat-file (beforethe previous line):

md "C:\Program Files\SolidWorks 2009\SolidWorks\Macros"

- Final step is to distribute this package to the users. If yousend it by mail you will probably have to zip it. Otherwise it willbe caught by an anti-virus filter due to the bat-file.

Hope it does what you need.
SF
SF 2009-05-05
Thanx Jorn

It will will for the time being... I hate to overwrite anything theindividual users may have changed on their macro toolbar...

I am still open to other ideas also...
SF
SF 2009-05-05
Dan,
If you have access to Visual Studio, it doesn't take much toswitch your macro code over to an add-in. The SDK template makes ita snap. That way you can actually deploy to multiple machines. Itdoes take a little more development effort, but it makes sharingthe code easier. Otherwise, I like Jorn's batch method.

FYI, you can edit the SLDREG files and remove any settings youdon't want to distribute. It is simply a registry file. That wayyou don't step on any of the customization a user has doneelsewhere.
JB
JB 2009-05-06
Mike,

You are of course right. A better option would be to create anadd-in.

When saving the SW settings it is possible to save only the macrotoolbar settings so you don't need to edit the reg-file to avoidother changes to user settings.

I was actually trying to interpret this section of the registry toidentify just the added buttons but as far as I can see/understandit is not possible to distribute registry information aboutspecific buttons only because the buttons has an ID-number whichwill then either dublicate an existing number at a different useror otherwise mess up the numbers for the user defined macro buttonsat the other users.
SF
SF 2009-05-06
go figure... the copy settings wizard doesnt work on my PC,it errors out...
JB
JB 2009-05-07
Dan,

You can manually make an export of the key
[HKEY_CURRENT_USER\Software\SolidWorks\SolidWorks 2008\User DefinedMacros] in the registry.

The result will be the same.
SF
SF 2009-05-07

Jorn Bjarning wrote:

 

Dan,



You can manually make an export of the key

[HKEY_CURRENT_USER\Software\SolidWorks\SolidWorks 2008\User DefinedMacros] in the registry.



The result will be the same.

Exporting that key only holds information on the macro infofor each button that is/was displayed on the macro toolbar. Youalso have to export
[HKEY_CURRENT_USER\Software\SolidWorks\SolidWorks 2007\UserInterface\Toolbars]. This key contains the info on what buttons aredisplayed on the macro toolbar.

JB
JB 2009-05-07
Dan,

You are of course right - sorry for the mistake. I was a little toofast...

SF
SF 2009-05-07
not a problem

thanx for the help
SF
SF 2009-05-08
This is exactly why SWTools was created....

http://angelsix.com/products/