API: Create toolbar from SWP-file: AddToolbarCommand2 (get cookie)

Hello All,

I'm trying to create a toolbar with a SWX macro (swp-file).

I can create a toolbar using AddToolbar, and I do see the buttons using AddToolbarCommand, but I just cannot assign a function to a button. I know how to do this using AddToolbarCommand2. But if I use this function in a SWX macro, a Cookie is required. But I don't know how to get the Cookie.

Has anyone done this before and/or has anyone have an example??

Thanks in advance for your reaction/help.

Kind regards,

JJ

Reply to
JJ
Loading thread data ...

No Idea! :-)

mvd

Reply to
Marcel & Liesbeth

AFAIK, you cannot create a Toolbar from a macro. The problem isn't the "cookie", but rather the "callback" functions you'll need to attach to each button. If you think about it, clicking a button in SolidWorks calls some compiled code, while you'd want to call the VBA interpreter, passing the name of a function as parameter. So it can't be the same kind of buttons, you'll need some special glue code to call the VBA code, and that's precisely the goal of the customizable Macro buttons. Now the question is : how to programmatically create Macro Buttons ? Till now I didn't find a way to do it. My solution today is to create the Macro buttons you need, then save the section(s) of the registry that hold this customization, and add the reg. file on target PC when installing the macro... There would be another solution : write a simple add-in that vreates the toolbar and buttons that call back the macro using SldWorks::RunMacro . You could define the buttons either in a .ini file or even from the macro itself by calling the add-in through SldWorks::CallBack... Did anyone already wrote this ?

Reply to
Philippe Guglielmetti

Hello Philippe,

Thanks for your reaction. What I did was: I created an add-in that reads out (*.swp) files in a (macro) directory. Based on the macro name, he shows/hides buttons. I did this with an add-in, but when using an add-in (even if you use one that has been created from scratch using the SDK) the performance to load a large assembly goes down tremendously (4x slower). What we tried is to use our PDM program to run a SWX macro to load/unload the add-in, but this seems to be unstable. That's why I am looking for a way to create a toolbar using a SWX macro (the one we can start using our PDM system).

I manage to create a toolbar using AddToolbar and AddToolbarCommand. It shows up, but defining the callback functions can only be done if a cookie is know. That's why I need the cookie. Now it crashes at this point. If I have a cookie, I can see if the callback functions will work.

Kind regards,

JJ

Philippe Guglielmetti schreef:

Reply to
JJ

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.