DrawHUDText returns a white box instead of a text?



  • Hi,

    This question is two fold

    1. Is there a way to properly display the DrawHUDText as text instead of a whitebox?
    2. Currently, the DrawHUDText disappears when I move the mouse. Is there a way to control when it will disappear and reappear again?

    Thank you for looking at my problem.

    You can see an illustration of the problem here:
    https://www.dropbox.com/s/0z8bv9b6becggmv/c4d132_HUD_draw_text.mp4?dl=0

    You can check the illustration code here

    import c4d
    from c4d import gui
    # Welcome to the world of Python
    
    
    # Main function
    def main():
        bd = doc.GetActiveBaseDraw()
        bd.DrawHUDText(100, 100, 'HUD Test')
        
        c4d.EventAdd()
    
    # Execute main()
    if __name__=='__main__':
        main()
    


  • hello,

    When you move the mouse or very often, the viewport is redraw so you have to redraw your text again.
    Even if it was working properly (not a white box) it should disappear at the next redraw.

    You are using a script and not drawing using the Draw() function called in a generator, scenehook, tag, tools, ... etc
    Scenehook are not accessible in python, they are a nice way to draw information on viewport.

    I've got a tag example that draw points information on viewport.

    Cheers
    Manuel.



  • @m_magalhaes

    Thanks for the response.
    Although I am a bit confused. You mentioned it is not possible in Python but you presented a Python Plug-in?

    This is what I understand so far

    1. You can't use the built-in DrawHUDText or Draw() function in Python. Use C++
    2. However, if you want to draw text in Python you can use DrawMultipleHUDText() instead?

    Can you confirm if this is the case?

    Anyhow, thanks for the tag code example. Sorry but I'm having a problem loading it.
    It presents an error

     File "C:\Program Files\MAXON\Cinema 4D R20\plugins\draw_text.pyp", line 62, in <module>
    icon=None)
    RuntimeError:Could not initialize global resource for the plugin.
    

    The code is referring to this portion of the code. Sorry I don't really know how to navigate the plug-ins api. Is there some additional procedure I should do for it to work?

        c4d.plugins.RegisterTagPlugin(id=PLUGIN_ID,
                                      str="Tag that draw on viewport",
                                      info=c4d.TAG_EXPRESSION | c4d.TAG_VISIBLE,
                                      g=TDRAW_EXAMPLE,
                                      description="tdrawexample",
                                      icon=None)
    


  • hiya,

    SceneHookPlugin. It's a type of plugin that you can't be created in python.

    Of course you can use the DrawHUDText in Python but you should use every draw possibilities (text, line, polygons) within a Draw() function that you override in your object (witch can be a tag, a generator, a tool etc..).

    Is it more clear ? Let me know i'll try to reformulate.

    ha, yes, about the error, you have to create a basic res directory with an empty description and string. Those files should be named 'tdrawexample' (.res, .str, .h)

    Cheers
    Manuel



  • @m_magalhaes

    Thanks for the response.
    RE: Of course you can use the DrawHUDText in Python but you should use every draw possibilities (text, line, polygons) within a Draw() function that you override in your object (witch can be a tag, a generator, a tool etc..).

    So, does this mean it is not possible with a script. Only a through plug-in. That's why you referred the tag plug-in as a solution right? Sorry. I don't really see a Python documentation for the Draw() function.

    RE: create a basic res directory.
    Thanks for the clarification. I tried making one, but still gives me a could not initialize error
    Here is the current directory is:
    https://www.dropbox.com/s/nd9mwvanmrxabkt/c4d132_HUD_draw_text_b.jpg?dl=0

    Thank you for looking at the problem.



  • hello @bentraje

    Sorry i should have linked you to the c++ Draw manual.

    About the directory structure you should have a look at this documentation

    something like so
    tree.JPG

    Cheers,
    Manuel



  • @m_magalhaes

    Thanks for the tree example. It loads successfully.
    But it gives an error of tdrawexample.str
    https://www.dropbox.com/s/rcr1xid9cqml92o/c4d132_HUD_draw_text_c.jpg?dl=0

    My concern is there is really nothing on .str file. Should I put something in there?



  • hey @bentraje,

    I've update the other thread with all information and files.
    In fact you always need a "minimum" in those files.

    Sorry for not being clear.

    Cheers
    Manuel



  • @m_magalhaes

    Thank you so much for the patience. It loads with no errors. Just one thing, how does it draw in the viewport?
    I guess the name of the tag will appear on the viewport?

    You can see the current state here:
    https://www.dropbox.com/s/pekm2msrut6f2ia/c4d132_HUD_draw_text_d.jpg?dl=0

    Sorry again for the trouble.



  • Don't worry :)

    the code prevent to work with non polygon object because we need to acces point position information with GetAllPoints

    if not op.IsInstanceOf(c4d.Opolygon):
                return c4d.DRAWRESULT_OK
    

    just edit your primitive. (by the way be carefull with the point number, it can be messy xD)

    Cheers
    Manuel



  • @m_magalhaes

    Thanks for the response! It works as expected. You can see the result here:
    https://www.dropbox.com/s/c4iivf56vaqzztk/c4d132_HUD_draw_text_e.jpg?dl=0

    Using the plug-in code you provided, I just replaced the DrawMultiple command to
    bd.DrawHUDText(50, 50, 'HUD Test')

    I see now what you mean by "the viewport is redraw so you have to redraw your text again."
    I tried adding print "Hello World" within the code and it prints every redraw.

    Will consider the thread as solved.

    Thanks again. Have a great day ahead!


Log in to reply