ClientResourceMap was introduced in Inventor 2022. This API allows users to set a list of client resources (like icons) for the browser pane for different themes.
STEP1
Make sure the Autodesk.inventor.interop.dll reference in your add in is the latest dll. You can do this by copying from the C:\Program Files\Autodesk\Inventor 2022\Bin\Public Assemblies to the /bin/debug/ directory of your Add in
STEP 2
Create a NameValueMap variable and a new Icon to it.
NameValueMap oNameValueMap;
oNameValueMap = app.TransientObjects.CreateNameValueMap();
oNameValueMap.Add("Icon", oIcon);
STEP 3
Create a ClientResourceMaps instance and initialize it as below
ClientResourceMaps clientResourceMaps;
clientResourceMaps = app.ClientResourceMaps;
NB: app is of type Inventor. Application
STEP 4
Add a new Client resource map through the ClientResourceMap instance and using the add() method
ClientResourceMap clientResourceMap;
clientResourceMap = clientResourceMaps.Add(clintId, 1);
NB: ClientID is a static string variable. In this case, is the same as the class ID of the Add in. However, It can be any unique string. The next parameter is an integer that will be the ID of the added resource
STEP 5
Use the setBrowserIconData() method to set the browser icon information and theme. Call this method for each Theme to set the icon data for that Theme, and in each browser icon data there should be an item that has the same name but a different icon for that Theme. The first argument is the NameValueMap variable you declared in Step 2, the next is the theme name as a string. The last variable is optional and is Boolean in nature. It specifies if the icon will be used as the default for the other themes if no icon data is provided for that theme. It is null by default.
clientResourceMap.SetBrowserIconData(oNameValueMap, "Dark");
Step 6
Create a clientNodeResource object and use the AddNodeResource() method to add a node resource with icon data from your clientResourceMap
ClientNodeResources oCnrs;
oCnrs = oDoc.BrowserPanes.ClientNodeResources;
ClientNodeResource oCnr;
oCnr = oCnrs.AddNodeResource(clientResourceMap.ClientId, 1, "Icon");
The AddNodeResource() method takes in 3 arguments. First is the ClientID as a string. In this case, I passed the same client ID I used in creating the clientResourceMap, the second is an integer which is the ID of the resource. The third argument is the string value which is the name of the Icon you want to use from your ClientMapResource list.
Step 7
Override the icon for the client feature and update the view
NativeBrowserNodeDefinition nativeNodeDef = oNode.BrowserNodeDefinition as NativeBrowserNodeDefinition;
if (nativeNodeDef != null)
nativeNodeDef.OverrideIcon = oCnr;
app.ActiveView.Update();
Before running the attached code sample make sure you change the following code to look for the .bmp image file in the right directory.
var image = Image.FromFile(@"C:\temp\clock.bmp");
stdole.IPictureDisp oIcon;
oIcon = PictureDispConverter.ToIPictureDisp(image);