Icon Button State



  • On 03/08/2018 at 09:25, xxxxxxxx wrote:

    Is there a way to modify the state of an icon to keep the button "pressed" while at an on state?

    I've made a script that hides and reveals things. But I want the icon state to remain highlighted when it's either on or off. Just like how the Selection Tools and most icons do already in the UI. Is that possible with a script icon?

    Thanks!



  • On 06/08/2018 at 02:02, xxxxxxxx wrote:

    Hi,

    no, currently there's no way to accomplish this for a script. But you can quite easily convert your script into a CommandData plugin, where you can then use the GetState() function. While the conversion from a script to a CommandData is actually simple (basically the script code just goes into Execute()), you may also consider using the Script Converter from Niklas Rosenstein's quick prototyping toolset, featured on our blog a while ago.

    And now, that Cinema 4D R20 got announced, I can also say, that with R20 Python scripts in Script Manager will also get the ability to set the menu state.



  • On 06/08/2018 at 07:07, xxxxxxxx wrote:

    Perfect! Thanks for the help Andreas



  • On 13/08/2018 at 11:33, xxxxxxxx wrote:

    Hey Motion4D did you succeed?

    I am also trying to set a highlight toggle for a python script icon based on it's state... I managed to convert it into a plugin but can't go any further... I found a few similar topics through the web but no real solution...

    If you have found a way I'd be glad to know it

    Cheers



  • On 14/08/2018 at 01:39, xxxxxxxx wrote:

    Hi Shallow_Red, first of all, welcome in the plugin cafe community!

    As Andreas explain in his previous post you have to useGetState to define your behavior.
    Here is a quick plugin example which toggles the icon if there is an object selected or not.

    import c4d
      
    # Be sure to use a unique ID obtained from www.plugincafe.com
    PLUGIN_ID = 1000001
      
    class MyCommandDataPlugin(c4d.plugins.CommandData) :
      
        def Execute(self, doc) :
            print 'Execute'
            return True
      
        def GetState(self, doc) :
            # If we get an object selected we can click on the Icon
            if doc.GetActiveObject() :
                return c4d.CMD_ENABLED
            else:
                return False
      
      
    if __name__ == "__main__":
        plugins.RegisterCommandPlugin(id=PLUGIN_ID, str="MyCommandDataPlugin",
                                      help="PMyCommandDataPlugin", info=0,
                                      dat=MyCommandDataPlugin(), icon=None)
    

    If you have any questions please, let me know :)
    Cheers,
    Maxime!



  • On 16/08/2018 at 09:00, xxxxxxxx wrote:

    Hi Maxime,

    Thanks for you reply, it helped a lot!

    What I was looking for was to return either c4d.CMD_ENABLED|c4d.CMD_VALUE when the plugin is on and c4d.CMD_ENABLED when off, and I found a way thanks to your link.

    Thanks again, I will try to search deeper before asking next time, but this really makes me want to crave into Python deeper.

    Cheers


Log in to reply