MSG_GETCUSTOMICON: Bitmap in IconData always empty



  • Hello,

    I want to change the icon of my plugin object, depending on settings in the BaseContainer. It should be the normal icon of the object, with a little overlay in the corner. Sounds easy, and 'm sure I have done this years ago. But now, I can't get it to work.

    The icon is set up with RegisterIcon during the register call. This works fine, the object does have the correct icon in the object manager.

    Bool RegisterMyObject()
    {
    	extern BaseBitmap * g_myIcons;
    	if (!RegisterIcon(ID_MYOBJECT, g_myIcons, 64, 0, 64, 64))
    		return false;
    	
    	maxon::String name = GeLoadString(IDS_MYOBJECT);
    	return RegisterObjectPlugin(ID_MYOBJECT, name, OBJECT_GENERATOR, MyObject::Alloc, "omyobject", AutoBitmap(ID_MYOBJECT), 0);
    }
    

    Now I want to change the icon, so in MyObject::Message(), I do:

    Bool MyObject::Message(GeListNode *node, Int32 type, void *data)
    {
    	switch (type)
    	{
    		case MSG_GETCUSTOMICON:
    		{
    			GetCustomIconData* const cid = static_cast<GetCustomIconData*>(data);
    			if (!cid)
    				return false;
    
    			// Let's see if the icon bitmap is there
    			BaseBitmap *iconBmp = cid->dat->bmp;
    			BaseBitmap *iconBmp2 = cid->dat->GetClonePart();
    
    			// What are the set flags?
    			ICONDATAFLAGS  iconDataFlags = cid->dat->flags;
    
    			break;
    		}
    	}
    
    	return SUPER::Message(node, type, data);
    }
    

    Strangely, iconBmpas well as iconBmp2 are correctly allocated, but are 0x0 pixels in size, and contain only black.
    iconDataFlags is ICONDATAFLAGS::NONE.

    Is that normal? I would have expected the bitmap to contain the icon of the object.

    I also tried, just for a test, to simply write into the bitmap by copying an existing icon of another object (that icon was also registered with RegisterIcon()):

    	BaseBitmap *originalIcon = AutoBitmap(ID_SOMEOTHEROBJECT);
    	originalIcon->CopyTo(cid->dat->bmp);
    	cid->filled = true;
    

    But that simply makes my object's icon vanish, and now the object has no icon.

    Also interesting, if I try to show any of the bitmaps (cid->dat->bmp, or cid->dat->GetClonePart(), or originalIcon) in the Picture Viewer with ShowBitmap(), I always get a 0x0 pixel black bitmap. Why is it empty? And why doesn't even the originalIcon work?

    Thanks for tips & advice!

    Cheers,
    Frank



  • According to the documentation, you can use GetIcon().

    See NodeData::Message() Manual.



  • Hi,

    thanks, I'll try that, too.

    Still, I really wonder why using AutoBitmap(ID_MYOBJECT) works when passing an icon the RegisterObjectPlugin(), but when I display the bitmap (or any bitmap from the IconData) in the Picture Viewer, it's 0 pixels in size.

    Cheers,
    Frank



  • Ah, GetIcon() seems to do something. I'll go with that!
    Thanks!



  • Hi Frank, sorry for coming late to the party, the API changed within the R21 where by default the icon is not more filled because it's up to you to fill it with what you need.

    Just in case for other people, not interested in C++ (since the manual is pretty obvious) there is a Python example in

    Where you can have custom icons, you can find an example of how to achieve custom icon within Python in py-custom_icon_r21.pyp.

    Cheers,
    Maxime.