CommandData Plugin DrawHUD
-
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 -
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. ABaseDraw
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: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,
FerdinandPS: When you just want to display status information, you should use the status bar related methods.
-
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