On 27/09/2013 at 12:11, xxxxxxxx wrote:
Scott, the GetState() method has nothing to do with the icon of the command. As littledevil
already pointed out, it doesn't matter whether you modify an icon which originates from
Cinema's own icon-table bitmap. You are only modifying the copy in the RAM, not the one
on the HD.
Download the full plugin
>
> _<_t_>_
>
>
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
> 11
> 12
> 13
> 14
> 15
> 16
> 17
> 18
> 19
> 20
> 21
> 22
> 23
> 24
> 25
> 26
> 27
> 28
> 29
> 30
> 31
> 32
> 33
> 34
> 35
> 36
> 37
> 38
> 39
> 40
> 41
> 42
> 43
> 44
> 45
> 46
> 47
> 48
> 49
> 50
> 51
> 52
> 53
> 54
> 55
> 56
> 57
> 58
> 59
> 60
> 61
> 62
> 63
> 64
> 65
> 66
> 67
> 68
> 69
> 70
> 71
> 72
> 73
>
> |
>
>
> import os
> import c4d
>
> def get_res_bitmap(filename) :
> bmp = c4d.bitmaps.BaseBitmap()
> result = bmp.InitWith(os.path.join(os.path.dirname(__file__), 'res', filename))
> if not result or result[0] != c4d.IMAGERESULT_OK:
> return None
>
> return bmp
>
> def set_icon(pluginid, bmp, overwrite_alpha=True) :
> icon = c4d.gui.GetIcon(pluginid)
> if not icon and bmp:
> return c4d.gui.RegisterIcon(pluginid, bmp)
> elif icon and not bmp:
> return c4d.gui.UnregisterIcon(pluginid, bmp)
> elif not icon:
> return
>
> 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
>
> class MyCommand(c4d.plugins.CommandData) :
>
> pluginid = 1000010 # TEST ID ONLY
> state = False
> bmp_a = get_res_bitmap('state-a.png')
> bmp_b = get_res_bitmap('state-b.png')
>
> def Register(self) :
> c4d.plugins.RegisterCommandPlugin(self.pluginid, "Icon Toggler", 0,
> None, "Execute to switch the icon of the command.", self)
> self.UpdateIcon()
>
> def UpdateIcon(self) :
> if not self.state:
> bmp = self.bmp_a
> else:
> bmp = self.bmp_b
> set_icon(self.pluginid, bmp)
>
> def Execute(self, doc) :
> self.state = not self.state
> self.UpdateIcon()
> return True
>
> if __name__ == "__main__":
> MyCommand().Register()
>
> <_<_t_>_
Best,
-Niklas