Addins Bitmaps

I know that there are several posts about people having issues with getting the bitmaps to work but I could not get a strait answer out of any of them. So i decided to make my own post.

I started off with the addin template that you can get from solidworks web site.

This is the code for getting the image paths as strings.

<p></p><p>cmdGroup = iCmdMgr.CreateCommandGroup(1, Title, ToolTip, <span style="color: #a31515;">""</span>, 3)</p><p>cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap(<span style="color: #a31515;">"AssemblyPricing.ToolbarLarge.bmp"</span>, thisAssembly)</p><p>cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap(<span style="color: #a31515;">"AssemblyPricing.ToolbarSmall.bmp"</span>, thisAssembly)</p><p>cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap(<span style="color: #a31515;">"AssemblyPricing.MainIconLarge.bmp"</span>, thisAssembly)</p><p>cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap(<span style="color: #a31515;">"AssemblyPricing.MainIconSmall.bmp"</span>, thisAssembly)</p>

And everything was working good until I tried to insert my own pictures then it stopped working. I even tried to switch it back to the original way with original pictures, and nothing. cmdGroup.... always comes back "". I have played with that for like a long time and nothing just cant get it to work.

So then after reading a few posts and some more playing I realized that it worked to just do this:

<p>cmdGroup = iCmdMgr.CreateCommandGroup(1, Title, ToolTip, <span style="color: #a31515;">""</span>, 3)</p><p>cmdGroup.LargeIconList = <span style="color: #a31515;">"C:\\Documents and Settings\\LM Cad\\My Documents\\LM-SoftWorks\\ToolbarLarge.bmp"</span></p><p>cmdGroup.SmallIconList = <span style="color: #a31515;">"C:\\Documents and Settings\\LM Cad\\My Documents\\LM-SoftWorks\\ToolbarSmall.bmp"</span></p><p>cmdGroup.LargeMainIcon = <span style="color: #a31515;">"C:\\Documents and Settings\\LM Cad\\My Documents\\LM-SoftWorks\\MainIconLarge.bmp"</span></p><p>cmdGroup.SmallMainIcon = <span style="color: #a31515;">"C:\\Documents and Settings\\LM Cad\\My Documents\\LM-SoftWorks\\MainIconSmall.bmp"</span></p>

Is there anything wrong with my last example that I should not do it that way ?

Why does the first example cause so much trouble ?

What is the main reason people cant get the first example to work ?

SolidworksApi macros
Answers 18
JC
JC 2009-08-07 Best Answer

Try include the images in the project

then

use

cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("AssemblyPricing.LM-SoftWorksLarge.bmp", thisAssembly)

cmdGroup.LargeIconList need a string

iBmp.CreateFileFromResourceBitmap will create it as aa string

BG
BG 2009-08-07

Jacob,

I changed LM-SoftWorksLarge.bmp back to the original images to avoid confusion.

But anyway what is wrong with what I have in my first example ?

All four of those files exist in my project with no spelling errors.

JC
JC 2009-08-07

try  change

cmdGroup = iCmdMgr.CreateCommandGroup(1, Title, ToolTip, "", 3)

to

cmdGroup = iCmdMgr.CreateCommandGroup(2, Title, ToolTip, "", 3)

or another number that you are not using

if that dose not work try

Sometime it get stuck in the Computer register

try delete to toolbar in regedit

BeCareful when in the regedit you can case your computer not to start

HKEY_CURRENT_USER\Software\SolidWorks\SolidWorks 2008\User Interface\Custom API Toolbars

in a sub Key (Folder)

look for

ModuleName={xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} this is the Add-in GUID

UserID=1 this is the bold number from above

then delete that key

BG
BG 2009-08-07

Your first suggestion did not make a difference. I tried about 4 different number and everytime it the pictures did not show.

Your second suggestion I could not find my addins GUID in the list in the registry.

JC
JC 2009-08-07
BG
BG 2009-08-07
Yes I am pretty sure I understand what you mean but my GUID does not appear in any of the ModuleNames
JC
JC 2009-08-07

Try a Build clean on the project

BG
BG 2009-08-07
I dont get it I have Solidworks open my toolbar loaded and I did a clean a build a rebuild all that great stuff and I still cannot find it in that list.
JC
JC 2009-08-07
Try Creating a new add-in to see if that one works
BG
BG 2009-08-07

I have 2 other test addins they both work fine I have hardly modified them from template and even they dont show up in that list but they work as expected.

JC
JC 2009-08-07

put a breakpoint in after

cmdGroup.LargeIconList = "C:\Documents and Settings\LM Cad\My Documents\LM-SoftWorks\ToolbarLarge.bmp"

then type intyour Immediate window

?cmdGroup.LargeIconList

is it the same as C:\Documents and Settings\LM Cad\My Documents\LM-SoftWorks\ToolbarLarge.bmp

when i Tried i using

cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("AssemblyPricing.ToolbarLarge.bmp", thisAssembly)

I got

C:\Documents and Settings\Jacob.cordingley\Local Settings\Temp\tmpCA1.tmp"

if so delete file then  see if that fix it

BG
BG 2009-08-07

If I type

cmdGroup.LargeIconList = "C:\Documents and Settings\LM Cad\My Documents\LM-SoftWorks\ToolbarLarge.bmp"

I get back

C:\Documents and Settings\LM Cad\My Documents\LM-SoftWorks\ToolbarLarge.bmp

when I type

cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("AssemblyPricing.ToolbarLarge.bmp", thisAssembly)

I get back

""

It is like it cant find the image.

JC
JC 2009-08-07

Make sure that

cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("AssemblyPricing.ToolbarLarge.bmp", thisAssembly)

AssemblyPricing is the name of your project

BG
BG 2009-08-07
Yes i am sure this is what my tree looks like.
comment imagecomment image
JC
JC 2009-08-07

Can you run the add-in as another user to see if it is user related

or

install it on another computer to see if it is computer related

BG
BG 2009-08-07
I definetly will try that it is time for me to leave work now so I will post update first thing monday morning. Thanks very much for your time Jacob.
SF
SF 2009-11-17

Actually I had this problem for a while as well. In my case I needed to right click the bitmap in the tree of your project > click on properties then in Advanced>Build Action you want to set it to Embedded Resource.

I think that should do the trick.

SF
SF 2009-11-18

Didn't bother reading all of the post. The reason it won't work is for one I noticed your setting LargeIconList and things to an actual string location of an image. This needs to be set to an actual ImageList object, and that image list had Images within it.

The way the Bitmap Handler class thing that SW provide in their template works is to load images stored as "Embedded Content" within a resource file of the assembly, and that name refers to the image resource name and any namespaces and folders to where the file is located.

I would recommend not using that at all and learning how to load resources yourself.