Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Lock / unlock plugin from Plugins menu

    Cinema 4D SDK
    3
    8
    1.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mfersaouiM
      mfersaoui
      last edited by mfersaoui

      Hi,
      Is it possible to lock a plugin in the Plugins menu using python. like image below:
      lock_plugin_gui.jpg
      I want to lock some of commands of my plugin depending on the selected object
      Thanks.

      1 Reply Last reply Reply Quote 0
      • CairynC
        Cairyn
        last edited by

        Override CommandData.GetState(doc) or ToolData.GetState(doc) to return a combination of
        CMD_ENABLED (enabled)
        CMD_VALUE (checked)
        or neither.

        mfersaouiM 1 Reply Last reply Reply Quote 0
        • mfersaouiM
          mfersaoui @Cairyn
          last edited by

          @Cairyn
          Thank you Cairyn,
          I had arrived at the result below :

          class MyCommand(c4d.plugins.CommandData):
              def __init__ (self):
                  self.isActive = False
          
              def Execute(self, doc):
                  ...
                  return True
          
              def GetState(self, doc):
                      if (self.isActive):
                          return c4d.CMD_ENABLED
                      else:
                          return c4d.CMD_VALUE
          

          Now I'm searching , how to swap from disabled to enabled depending on the type of the selected object in Object Manager.

          mfersaouiM 1 Reply Last reply Reply Quote 0
          • mfersaouiM
            mfersaoui @mfersaoui
            last edited by mfersaoui

            @mfersaoui
            I found this solution:

            def GetState(self, doc):
                    op = doc.GetActiveObject()
                    if op is not None and op.GetType() == OBJECT_ID:
                        return c4d.CMD_ENABLED
                    else :
                        return False
                        
            
            1 Reply Last reply Reply Quote 0
            • M
              m_adam
              last edited by

              Hi @mfersaoui while True, False is supported it's better to return the correct value from the symbols (CMD_ENABLE) since in any case your bool will be converted to an Int and in the future value may change while symbols will remain the same.

              Moreover in R20 GetState is also available for script in the Script Manager.

              Cheers,
              Maxime.

              MAXON SDK Specialist

              Development Blog, MAXON Registered Developer

              mfersaouiM 1 Reply Last reply Reply Quote 0
              • mfersaouiM
                mfersaoui @m_adam
                last edited by

                @m_adam
                Thank you Maxime, I had used the (return False) because this give a different result visual of the icon.
                preview:
                GetState_result.jpg
                Result (1) gived when use : return c4d.CMD_VALUE
                Result (2) gived when use : return False

                CairynC 1 Reply Last reply Reply Quote 0
                • CairynC
                  Cairyn @mfersaoui
                  last edited by

                  @mfersaoui You misunderstand the return value.

                  This is not a single true/false flag, but a set of flags. As I mentioned, CMD_ENABLED stands for the enabling of the command (greyed out if not set), and CMD_VALUE stands for the checked state (in case of icons, the background changes, as you saw in your test). These two flags are not mutually exclusive but can be used together! (use or to join).

                  The actual value to use if you want neither flag set is simply 0. False works in this case because the numeric equivalent of false is 0.

                  import c4d
                  from c4d import gui
                  
                  def state():
                      op = doc.GetActiveObject()
                      if op is not None:
                          if op.GetType() == c4d.Ocube :
                              return c4d.CMD_ENABLED | c4d.CMD_VALUE
                          elif op.GetType() == c4d.Ocylinder :
                              return c4d.CMD_VALUE
                          else :
                              return c4d.CMD_ENABLED
                      return 0
                  
                  # Main function
                  def main():
                      print "Triggered!"
                  
                  # Execute main()
                  if __name__=='__main__':
                      main()
                  

                  If you watch the above script as icon in a toolbar, you will see all four state combinations depending on what primitive you select. If nothing is selected, the icon is grayed out. If you select a cylinder, the icon is still grayed out and unselectable but the background changes to make clear it's checked. A cube will show both the checked and active states, and some other object will show only the active state.

                  To be fair, the standard default script in R20 mentions False explicitly though.

                  mfersaouiM 1 Reply Last reply Reply Quote 1
                  • mfersaouiM
                    mfersaoui @Cairyn
                    last edited by

                    @Cairyn Thank you for your detailed reply.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post