Hi everyone,
I am adding the icons to the menus and toolbars. The single icon is getting repeated in multiple commands for a single command group. The image is attached here
Here is my code snippet:
SW.ICommandGroup cmdGroup = CmdMgr.CreateCommandGroup2(MainCmdGroupId + (count++), title, toolTip, "", -1, ignorePrevious, ref cmdGroupErr);
string ImageDataPath = "E:\\Laxman Programs\\Test Images";
var playPath = ImageDataPath + @"\play.png";
var seekPath = ImageDataPath + @"\SeekStart.png";
var seekEndpath = ImageDataPath + @"\SeekEnd.png";
var partingpath = ImageDataPath + @"\partingline.png";
var pausePath = ImageDataPath + @"\Pause.png";
var warningPath = ImageDataPath + @"\warning.png";
icons[0] = playPath;
icons[1] = seekPath;
icons[2] = seekEndpath;
cmdGroup.IconList = icons;
// cmdGroup.MainIconList = mainIcons;
cmdIndex0 = cmdGroup.AddCommandItem("Create Layout", locationIndex++, "Create Layout", "Create Layout", 0, "CreateLayout", "EnableCommanMenu", 12);
cmdIndex1 = cmdGroup.AddCommandItem("Identify Elements", locationIndex++, "Identify Elements", "Identify Elements", 1, "IdentifyElements", "EnableCommanAxwMenu", 12);
var materialGroup = CmdMgr.CreateCommandGroup2(MainCmdGroupId + (count++), title + "\\Specify Materials", "Specify Materials", "", locationIndex++, ignorePrevious, ref cmdGroupErr);
icons = new string[3];
icons[0] = partingpath;
icons[1] = pausePath;
icons[2] = warningPath;
materialGroup.IconList = icons;
mtrIndex0 = materialGroup.AddCommandItem("Material 1", -1, "Material 1", "Material1", 0, "EditMaterial", "EnableCommanMenu", 12);
mtrIndex1 = materialGroup.AddCommandItem("Material 2", -1, "Material 2", "Material 2", 1, "EditMaterial", "EnableCommanMenu", 12);
I am not clear about the ImageListIndex in AddcommandItem. From which list we have to set the index.
Here I am just using the hardcoded paths for images. How to use the bit map images from the project Resource
folder? I am trying to access it by using the Properties.Resource.image but it returns the bitmap and the above lists need the icon paths (string).
Hi Laxman,
Basically, if you have toolbar with 10 icons for SW 2016 and older you should have 2 bitmaps (not png)
First would be 160x16 (i.e. 10 icons of 16x16 aligned in a row) (which is called small icons list)
Second would be 240x24 (i.e. 10 icons of 24x24 aligned in a row) (which is called large icon list)
For newer versions of SOLIDWORKS you will need to have high res icons (you still can use old icons but it won't take benefit of high res which is now supported). For that you need
200x20 (10 icons of 20x20)
....
1280x128 (10 icons of 128x128)
In summary, all icons in all those 10 files are repeated just in different sizes. It is not that big problem unless you are not planning to add too many icons or change them or need to develop several add-ins...
I know I have mentioned this to you before (so I apologize for repeating), but this is why I have developed SwEx. So with that framework you can have single icon (doesn't even need to be square of any size, something like 256x256 and framework will do the rest, it will scale icon for needed sizes, compose it etc. - all behind the scenes) so you won't need to do anything. So for example this how the code would look for 3 buttons:
[Icon(typeof(Resources), nameof(Resources.export))]
public enum ExportCommands_e
{
[Icon(typeof(Resources), nameof(Resources.export_parasolid))]
Parasolid,
[Icon(typeof(Resources), nameof(Resources.export_iges))]
Iges,
[Icon(typeof(Resources), nameof(Resources.export_step))]
Step
}
where export_parasolid, export_iges, export_step are just 3 png images of any size in the resources (no need to stack them in one line, no need to fit them in a specific size or use gray as transparency key, just any png as you would normally use in any windows application). You can get some project examples here: solidworks-api-examples/swex/add-in at master · codestackdev/solidworks-api-examples · GitHub.
I'm going to stop supporting this framework soon as I have switched it to a new xCAD framework which has way more functionality and adapted to the modern .NET (i.e. .NET Standard and .NET Core). It is already published and available, but I haven't published complete documentation yet, just some small snippets. But you can look at this demo to see it in full action: Implementing SOLIDWORKS® Top Ten List Ideas 2020 from scratch using xCAD.NET - YouTube