On 28/04/2017 at 08:41, xxxxxxxx wrote:
Originally posted by xxxxxxxx
at what point does our documentation give the impression you could use GetIcon() to change the icon of for example Null objects? We'd need to clarify this, as you can't.
Even if it's bad and I really discourage to use it in production since it can literally kill the UI and user don't really like that !
But you can do it
import c4d
#https://plugincafe.maxon.net/topic/7462/9284_change-icon-based-on-state-in-commanddata
#Func by niklas
def set_icon(pluginid, bmp, overwrite_alpha=True) :
icon = c4d.gui.GetIcon(pluginid)
if not icon:
return c4d.gui.RegisterIcon(pluginid, bmp)
ref = icon['bmp']
w, h = icon['w'], icon['h']
temp = c4d.bitmaps.BaseBitmap()
if temp.Init(w, h, bmp.GetBt()) != c4d.IMAGERESULT_OK:
return False
bmp.ScaleIt(temp, 256, True, True)
a1 = a2 = None
if overwrite_alpha:
a1 = ref.GetInternalChannel()
a2 = temp.GetInternalChannel()
for x in xrange(w) :
rx = x + icon['x']
for y in xrange(h) :
ry = y + icon['y']
ref[rx, ry] = temp[x, y]
if a1:
if a2:
alpha = temp.GetAlphaPixel(a2, x, y)
else:
alpha = 255
ref.SetAlphaPixel(a1, rx, ry, alpha)
return True
def main() :
fn = c4d.storage.LoadDialog()
if not fn: return
bmp = c4d.bitmaps.BaseBitmap()
res = bmp.InitWith(fn)[0]
if res != c4d.IMAGERESULT_OK:
return
set_icon(c4d.Onull, bmp)
c4d.gui.GeUpdateUI()
c4d.EventAdd()
if __name__=='__main__':
main()
But again avoid this !!!
But it can be a lazy method for modifing your icon of your plugin.
For more detail have a look at my tutorial here
(it's in french)
Another thing take a look at this plugin which can be a kind of what you want.
https://github.com/NiklasRosenstein/c4d-container-object