After undo, point object SetAllPoints not update
-
Hi,
I encountered a problem. When I set the position of an object's point, however, when I undo it and set it again, the object does not refresh in time. Only if I click on the object again and set it again will it be refreshed in time.This is the video,
-
Hello @chuanzhen,
Thank you for reaching out to us. The problems you encounter stem from the fact that you use the wrong method to retrieve your link.
When you undo an action, the object will not be the same anymore since the object has been replaced with whatever was found in the undo-stack. You simply must use the correct method
c4d.gui.LinkBoxGui.GetLink
and things will also work after an undo.Cheers,
FerdinandCode:
def CreateLayout(self): self.SetTitle("test") self.GroupBegin(1000, c4d.BFH_SCALEFIT, 4, 0) self.AddStaticText(1003, c4d.BFH_RIGHT, 80, 20, " Target ") # We store the custom GUI so that we do not have to grab it every time. self._link = self.AddCustomGui( 1004, c4d.CUSTOMGUI_LINKBOX, "", c4d.BFH_SCALEFIT, 300, 0, c4d.GetCustomDataTypeDefault(c4d.DTYPE_BASELISTLINK)) self.GroupEnd() self.AddButton(1010, c4d.BFH_SCALEFIT, 150, 30, "ChangePoints") return True def Command(self, id, msg): if id == 1010: doc = c4d.documents.GetActiveDocument() # This line was problematic because you did use BaseCustomGui.GetData and not # LinkBoxGui.GetLink which has special logic for this type. This can fail. # target = self.FindCustomGui(1004, c4d.CUSTOMGUI_LINKBOX).GetData() # This cannot, it will automatically reattach a dangling link (after an undo for # example). We could also do that ourself with UUIDs but why when we do not have to :) target: c4d.BaseObject | None = self._link.GetLink(doc, c4d.Opolygon) if not target: return True points: list[c4d.Vector] = [c4d.Vector() for _ in range(target.GetPointCount())] doc.StartUndo() doc.AddUndo(c4d.UNDOTYPE_CHANGE, target) target.SetAllPoints(points) target.Message(c4d.MSG_UPDATE) doc.EndUndo() c4d.EventAdd() return True
-
@ferdinand Thanks for your help!