BaseContainer::setString and undo



  • On 23/05/2013 at 02:07, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   14 
    Platform:   Windows  ;   Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    I am trying to set a single custom string data in a document ready for undo/redo by doing:

    doc->StartUndo();

    doc->AddUndo(UNDOTYPE_???, ptr???);

    doc->GetDataInstance()->SetString(<Some ID>, "VALUE");

    doc->EndUndo();

    1. Is SetString using the BaseContainer the right and preferred way of doing this?

    2. What UNDO_TYPE??? do I have to supply for this?

    3. Most interesting what void * ptr do I have to supply for this?

    4. Is there a way to abort the change rather than only commit the change?



  • On 23/05/2013 at 02:20, xxxxxxxx wrote:

    Welcome to the forum, Ralf.

    1. Sure, or do you see any other method for it?
    2. UNDOTYPE_CHANGE_SMALL can be used for changes on the container.
    3. The object whoose container you are about to modify
    4. I don't get that question, sorry.

    Best,
    -Nik



  • On 23/05/2013 at 02:39, xxxxxxxx wrote:

    Hi Niklas,

    thank you.

    2. This was my guess too.
    3. When I give GetDataInstance(), I get an exception.
       When I give doc, I get no exception but AddUndo returns false.
    Therefore I don't see an entry in the menu "Edit -> Undo" like when I create e.g. a cube.
    4. Like transactions. The transaction is started, many changes are made initiated from different places in the source code and then suddenly an error occurs and all the changes should be aborted and reverted back to the state when the transaction has started.

    Best regards,
    Ralf



  • On 23/05/2013 at 07:38, xxxxxxxx wrote:

    3. You are modifieng doc, so you have to pass doc as the second parameter. However, I have
    never tried adding an undo to the document itself. I can't get it to work from Python either.

    StartUndo()/EndUndo() are called implicitly for a script.

    import c4d
      
    print doc.AddUndo(c4d.UNDOTYPE_CHANGE, doc)
    doc[c4d.DOCUMENT_FPS] = 25
    c4d.EventAdd()
    

    Note that some parameters on objects have to be set using SetParameter(), like DOCUMENT_FPS
    on the document. Using the [] syntax is equal to SetParameter() in C++. If you notice a value
    doesn't change after setting data to the container, use SetParameter() instead.
    **
    **
    Maybe someone else knows why?

    4. You can use BaseDocument::DoUndo().



  • On 23/05/2013 at 08:10, xxxxxxxx wrote:

    I think the project settings / documents settings are actually a own GeListNode, like
    for example the WorldColorContainer. So you have to grab and pass that node instead.

    Peeking into BasePlugins with 'project' in its repr. Too lazy to investigate it further, but
    the 'Project Settings' node looks promising.

    import c4d
    from c4d import plugins
      
    def main() :
        plug = c4d.plugins.GetFirstPlugin()
        while (plug != None) :
            if 'project' in repr(plug) :
                print plug
            plug = plug.GetNext()
      
    if __name__=='__main__':
        main()
      
    <c4d.plugins.BasePlugin object called 'Send project back...' with ID 4 at 0x0000000007128410>
    <c4d.plugins.BasePlugin object called 'Detach Projection Plane' with ID 4 at 0x00000000071283F0>
    <c4d.plugins.BasePlugin object called 'Project on Hidden Polygons' with ID 4 at 0x0000000007128410>
    <c4d.plugins.BasePlugin object called 'Projects' with ID 4 at 0x00000000071283F0>
    <c4d.plugins.BasePlugin object called 'Next Project' with ID 4 at 0x0000000007128410>
    <c4d.plugins.BasePlugin object called 'Project Settings...' with ID 4 at 0x0000000007128410>
    <c4d.plugins.BasePlugin object called 'Save Project with Assets...' with ID 4 at 0x00000000071283F0>
    <c4d.plugins.BasePlugin object called 'Project Info...' with ID 4 at 0x0000000007128410>
    <c4d.plugins.BasePlugin object called 'Project' with ID 4 at 0x00000000071283F0>
    <c4d.plugins.BasePlugin object called 'Previous Project' with ID 4 at 0x0000000007128410>
    <c4d.plugins.BasePlugin object called 'Projection Painting' with ID 4 at 0x00000000071283F0>
    <c4d.plugins.BasePlugin object called 'Apply Projection' with ID 4 at 0x0000000007128410>
    <c4d.plugins.BasePlugin object called 'Discard Projection' with ID 4 at 0x00000000071283F0>
    

    happy rendering,
    ferdinand


Log in to reply