Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    CommandData Plugin DrawHUD

    Cinema 4D SDK
    s26 python
    3
    3
    461
    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.
    • gheyretG
      gheyret
      last edited by

      Hi Everyone!
      I want to Draw HUD in the viewport using CommandData Plugin. And i put my 'draw' function in to CommandData.GetState(self, doc)
      but nothing happend in the viewport.
      And the code like this:

      import c4d
      
      
      _Plugin_id = 20230616
      _Plugin_name = "Command_Test"
      
      
      class Command(c4d.plugins.CommandData):
      
          def __init__(self):
              self.a = False
      
          def Execute(self, doc):
              if self.a:
                  self.a = False
              else:
                  self.a = True
              print(self.a)
      
              return True
      
          def GetState(self, doc):
              if self.a:
                  print(123)
                  bd = doc.GetActiveBaseDraw()
                  bd.SetMatrix_Screen()
                  bd.DrawHUDText(50,50, "Test HUD")
                  
                  return c4d.CMD_VALUE | c4d.CMD_ENABLED
              else:
                  return c4d.CMD_ENABLED
      
      if __name__ == '__main__':
          c4d.plugins.RegisterCommandPlugin(id=_Plugin_id, str=_Plugin_name, 
                                      info=0, icon=None, help='', dat=Command())
      

      And there have another problem: you can see the "print(123)" in the GetState
      method for testing, when i click my plugin, cinema4d can print correctly and continuosly in the console, but if i move my mouse to the viewport or click somewhere (like refreshing maybe), the cinema4d has been stucking.
      I don't know if I'm wrong or misunderstood something

      www.boghma.com

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @gheyret
        last edited by ferdinand

        Hey @gheyret,

        Thank you for reaching out to us.

        I want to Draw HUD in the viewport using CommandData Plugin.

        In short: you cannot draw from a CommandData plugin. A BaseDraw is a container for drawing instructions among other things, not an entity which is actually drawing. When Cinema 4D does not request drawing instructions, you can enqueue as many as you want, they will be ignored. The C++ documentation is even a bit stricter in its wording:

        85c02f44-1586-4dc2-b2a2-b5b6d9806549-image.png

        The plugin hooks which provide Draw methods in Python are:

        • c4d.plugins.FalloffData
        • c4d.plugins.ToolData
        • c4d.plugins.TagData
        • c4d.plugins.ObjectData

        In C++ you can also draw with other things such as a ScenehookData which allows for drawing without a tangible entity such as a tool, object, or tag. The best way to emulate this in Python is to use a hidden object.

        But you are then still bound to the drawing routine cycle of Cinema 4D. So, when you think that you should print "Hello World!" to the screen, it could still be seconds until Cinema 4D requests drawing instructions from your object.

        Because as stated above, with BaseDraw you do not carry out the drawing, you only fill the drawing instructions buffer.

        Cheers,
        Ferdinand

        PS: When you just want to display status information, you should use the status bar related methods.

        MAXON SDK Specialist
        developers.maxon.net

        J 1 Reply Last reply Reply Quote 1
        • J
          jana @ferdinand
          last edited by

          Hello @gheyret ,

          without further questions or postings, we will consider this topic as solved by Friday, the 11th of august 2023 and flag it accordingly.

          Thank you for your understanding,
          Maxon SDK Group

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