AddUndo() for MergeDocument() ?



  • Hi,

    first of all: If you want to use threads, you should use c4d.threading.C4DThread and not Pythons builtin thread type or weird things might happen. Also note that threading comes with certain limitations:

    For all threaded functions it is forbidden to:

    • Add an event.
      [...]
    • Change the structure of objects attached to the document.
      [...]
    • Create undos.

    I am also not quite sure what the purpose of your thread is, since you are loading into the active document. If you want to "load in the background" you will have to use a temporary document. But for loading just one file I do not see any performance benefits, since you have to merge that temporary document into the active document at the end.

    Cheers
    zipit



  • hello,

    well as @zipit said it's forbidden to change the structure of a document outside the main thread.
    watch this page and the warning about threading

    I did checked the StartUndo and it's using GeIsMainThreadAndNoDrawThread and just get out.
    So it's pretty clear that you can't add undo on a thread.

    why are you using thread here ?

    Cheers,
    Manuel



  • This post is deleted!


  • @m_magalhaes @zipit
    I use thread to manipulate external pipes(subprocess etc).



  • @arsen said in AddUndo() for MergeDocument() ?:

    @m_magalhaes @zipit
    I use thread to manipulate external pipes(subprocess etc).

    Hi,

    although I am aware of the concept of pipes, this does not really clear anything up for me 🧐. What do you mean by external and manipulate? Just for clarification: Under pipes I understand a data IO interface to communicate between different processes, provided in Python for example by os.pipe().

    And I don't really get why this forces you to use a thread to import an obj file 🤔.

    Cheers
    zipit



  • @zipit
    Hi
    I use thread to track the external file. When a file is changed, it is imported.
    When using c4d.threading, subprocess.Popen() / time.sleep() freezes C4D ( until the process is complete )



  • Hi,

    ah, ok, I do understand your problem better now ;). Well as explained in this thread your cannot load files other than from the main thread of c4d.

    You could do however the following:

    1. Use processes, threads or whatever you would like to use to monitor the status of your file(s).
    2. Use some cross-process communication interface like os.pipe() to indicate when your data has changed.
    3. Implement 1. and 2. within a MessageData plugin.
    4. Use MessageData.GetTimer and MessageData.CoreMessage to periodically peek into your pipe and then react to its status from the main thread/ the c4d process.

    Cheers
    zipit



  • hello,

    @zipit already make another nice answer.

    I can just add that in c++ you have also a filemonitor manual where you can use the function WatchDirectory

    Cheers,
    Manuel



  • @zipit @m_magalhaes
    Thanks for the answers! I figured out how to solve the problem.



  • hi,

    nice, feel free to share your solution and mark this thread as solved.

    Cheers,
    Manuel


Log in to reply