Plugins in plugin OR icons!!!!!



  • On 27/04/2017 at 07:29, xxxxxxxx wrote:

    Hello world! A small question has matured. Please tell me whether it is possible to replace the icons (nulls as example). The documentation says that you can use GetIcon, but it's not clear how. I'm writing a small rig and I need parts of the rig to be in the same style (5 icons and the main icon on the plugin). If there are examples, I will be grateful. Or is it not possible without registering each element. Then the question arises how to make a plugin with the attachment of small plugins)))))))))))) Thanks in advance!



  • On 28/04/2017 at 07:33, xxxxxxxx wrote:

    Hi,

    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.

    Or you could implement your own custom Null object (ObjectData) and in there you'd implement Message() reacting to MSG_GETCUSTOMICON. By this you can change the icon of any instance of your custom Null individually or rather the other way round, C4D asks you for an icon of each individual instance of your object in the scene. Unfortunately I have nothing in Python docs on this, but at least the NodeData manual in C++ docs provides a code snippet.

    Lastly depending on your needs, it may be enough to make use of the built-in icon coloring of Null objects. This just boils down to setting parameters.



  • 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 https://vimeo.com/190940660 (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


Log in to reply