The icon of pushbutton is not displayed

The icon of pushbutton is not displayed

choshQT24J
Enthusiast Enthusiast
576 Views
6 Replies
Message 1 of 7

The icon of pushbutton is not displayed

choshQT24J
Enthusiast
Enthusiast

I have tried several ways for setting image of pushbutton. 

none of them worked. Is it a bug? ( revit2024)

var image = new BitmapImage(new Uri("pack://application:,,,/MyProject;component/Resources/icon128x128.png"));

PushButtonData buttonData = new(name, text, thisAssemblyPath, className);
buttonData.ToolTip = tooltip;
PushButton pushButton = ribbonPanel.AddItem(buttonData) as PushButton;
pushButton.LargeImage = image;

 

0 Likes
Accepted solutions (1)
577 Views
6 Replies
Replies (6)
Message 2 of 7

moturi.magati.george
Autodesk
Autodesk

Hi @choshQT24J,

Kindly try to add your icon to the resources first i.e., right click on your project, go to properties, go to Add Resource and select new image.

You can then try to use the code below:

Image img = Properties.Resources.icon128x128;
ImageSource imgsrc=GetImageSource(img);
PushButtonData btnData = new PushButtonData( name, text,thisAssemblyPath,thisAssemblyPath)
{
    ToolTip = tooltip,
    LongDescription = "",
    Image = imgSrc,
    LargeImage = imgSrc
};
PushButton pushButton = ribbonPanel.AddItem(btnData) as PushButton;

 

  Moturi George,     Developer Advocacy and Support,  ADN Open
0 Likes
Message 3 of 7

choshQT24J
Enthusiast
Enthusiast

Is this the only proper way?

For the way I used,

I have set my icon into the resource.

And there is no compile error or running error.

My understanding is that my icon is set up correctly without any execution errors, but it just doesn't get displayed.

If I did not add it as a resource it would be an execution error.

0 Likes
Message 4 of 7

moturi.magati.george
Autodesk
Autodesk

Hi @choshQT24J,

You can also have a look at your icon resolution and resize it appropriately.

https://www.revitapidocs.com/2018/34d5d65e-d835-74ec-7c67-22b3b1c684f5.htm
https://www.revitapidocs.com/2018/558a403d-2002-10e9-30d8-c0160f5115dc.htm

  Moturi George,     Developer Advocacy and Support,  ADN Open
0 Likes
Message 5 of 7

choshQT24J
Enthusiast
Enthusiast

I have also tried to resize to 32x32. Not work.

And the link you provide said "If the image is larger it will be adjusted to fit the button".

0 Likes
Message 6 of 7

Mohamed_Arshad
Advisor
Advisor
Accepted solution

Hi @choshQT24J 

 

Two things you have to update in Icon.

1. Icon Size (32x32 Pixels)

2. Icon Dpi to 96-100.

then it will fit in your button.

 

Hope this will helps 🙂

 


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 7 of 7

choshQT24J
Enthusiast
Enthusiast

Thanks Mohamed_Arshad! You save my life.
I did not know it also limit by dpi. So terrible implemention of the API!