Add-in Icons
The add-in icon displays next to the add-in name in the SolidWorks Add-in
Manager dialog.
SolidWorks supports add-in icons
that are 32-bit PNG and BMP files with alpha channel. SolidWorks recommends that
you consult the internet and books containing information about creating
transparent images with alpha channel.
Add-in icons must be 16x16 pixels in size.
The add-in loads its icon in the following order of preference:
- Icon file at registry-specified location:
Version-specific:
HKEY_LOCAL_MACHINE\SOFTWARE\SolidWorks\SolidWorks version\Addins\{CLSID}\Icon
Path
Version-independent:
HKEY_LOCAL_MACHINE\SOFTWARE\SolidWorks\AddIns\{CLSID}\Icon
Path
NOTE: You can specify
Icon Path
using the icon image's file name and its
full path, its UNC path, or the path relative to where the add-in's DLL is
located.
In SolidWorks 2013 SP0, and later, you can use a path relative to the
SolidWorks install_dir folder (typically C:\Program
Files\SolidWorks Corp\SolidWorks) in
Icon Path.
Specify the relative path and the file name of the add-in's icon; for
example:
subfolder1\subfolder2\image.png
- PNG file whose name matches the DLL name and resides in
the DLL folder
- BMP file whose name matches the DLL name and resides in
the DLL folder
If the add-in icon file resides in a folder other than the add-in project DLL
folder, it must be explicitly registered in SwAddin.RegisterFunction() as
follows:
#region SolidWorks Registration
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type t)
{
Microsoft.Win32.RegistryKey hklm = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey hkcu = Microsoft.Win32.Registry.CurrentUser;
string keyname = "SOFTWARE\\SolidWorks\\Addins\\{" + t.GUID.ToString() +
"}";
Microsoft.Win32.RegistryKey addinkey = hklm.CreateSubKey(keyname);
addinkey.SetValue(null, 0);
addinkey.SetValue("Description", SWattr.Description);
addinkey.SetValue("Title", SWattr.Title);
#region Extract icon during registration
BitmapHandler iBmp = new BitmapHandler();
Assembly thisAssembly;
thisAssembly = System.Reflection.Assembly.GetExecutingAssembly();
String tempPath =
iBmp.CreateFileFromResourceBitmap("_2012_PMP_Interfaces.AddInMgrIcon.bmp",
thisAssembly);
// Copy the bitmap to a suitable permanent location with a meaningful
filename
String addInPath =
System.IO.Path.GetDirectoryName(thisAssembly.Location);
String iconPath = System.IO.Path.Combine(addInPath, "AddInMgrIcon.bmp");
System.IO.File.Copy(tempPath, iconPath, true);
// Register the icon location
addinkey.SetValue("Icon
Path", iconPath );
#endregion
keyname = "Software\\SolidWorks\\AddInsStartup\\{" + t.GUID.ToString() +
"}";
addinkey = hkcu.CreateSubKey(keyname);
addinkey.SetValue(null, Convert.ToInt32(SWattr.LoadAtStartup),
Microsoft.Win32.RegistryValueKind.DWord);
}
Changes to the icon file or registry take effect only after SolidWorks is
restarted.
The .NET add-in templates deliver add-in icon files called AddinIcon.bmp
to the same folder as the .NET project class files. During compilation, this
file is copied, renamed to match the DLL name, and registered in the same folder
where the DLL resides. At runtime, AddinIcon.bmp displays next to the
add-in in the Add-in Manager dialog.
To learn more about add-ins and their menu items and toolbars: