SOLVED Undo Problem For TagData Plugin

Hey folks,

I encountered Undo related issue again. It might be due to my lack of understanding for undo things but let me ask you a question.

I wrote a test tag plugin with python which follows another object's position with a little offset.
It simply works but when I undo, the object that has the tag doesn't react until I click somewhere (see below).

Is it possible to solve this issue with python?
I know undo things are prohibited in execute() of tagdata, so is there any workaround?

Please help me if you know the solution.

undo_issue_1.gif

Here's quick code for this.

testtag.pyp

import os
import c4d
from c4d import plugins, bitmaps, utils


PLUGIN_ID = *******


class TestTagData(plugins.TagData):
    def Init(self, node):
        pd = c4d.PriorityData()
        if pd is None:
            raise MemoryError("Failed to create a priority data.")
        pd.SetPriorityValue(lValueID = c4d.PRIORITYVALUE_MODE, data = c4d.CYCLE_INITIAL)
        node[c4d.EXPRESSION_PRIORITY] = pd
        return True

    def Execute(self, tag, doc, op, bt, priority, flags):
        bc = tag.GetDataInstance()
        obj = bc.GetLink(c4d.TTEST_TARGET_OBJECT)
        if obj is None:
            return False
        mrx = obj.GetMg()
        mrx.off += c4d.Vector(100, 0, 0)
        op.SetMg(mrx)
        return c4d.EXECUTIONRESULT_OK


if __name__ == "__main__":
    plugins.RegisterTagPlugin(id = PLUGIN_ID, str = "Test Tag", info = c4d.TAG_EXPRESSION | c4d.TAG_VISIBLE, g = TestTagData, description = "ttest", icon = None)

ttest.res

CONTAINER Ttest
{
    NAME Ttest;
    INCLUDE Texpression;

    GROUP ID_TAGPROPERTIES
    {
        LINK TTEST_TARGET_OBJECT
        {
            ANIM ON;
            ACCEPT { Obase; };
        }
}

hi,

this is probably a bug here, i need to investigate a bit more.
Instead of retrieving the object using the BaseContainer, use the bracket notation.

You will receive the right object with the correct Matrix.

obj = tag[c4d.TTEST_TARGET_OBJECT]

Cheers,
Manuel

@m_magalhaes Thank you for your checking, Manuel.

I didn't think it's a bug! And yep, your workaround with bracket notation works fine.
So these bracket notation style is safer than using BaseContainer in any case?
Anyway, let us know if you confirm this is a bug.

hi,

@beatgram said in Undo Problem For TagData Plugin:

So these bracket notation style is safer than using BaseContainer in any case?

this should be exactly the same.
Sorry i didn't got time to warp my head around it.

Cheers,
Manuel