Hello Justin ^_^ I apologize for my ignorance earlier today. I am now able to properly delete and undo, and automatically create a new MObject to track the unique name. Upon class initialization, a UUID is generated. If the node is deleted and the MObject becomes None, at this point, I can regenerate the name using the UUID, and then recreate the MObject. Thank you once again for your help!
在2024年5月11日星期六 UTC+8 16:54:23<Kangd dan> 写道: > Thank you!! I just hope that it can work like pymel. When I delete an > object and then undo it, I can still work normally. > So I don't know if pymel did not delete the MOobject path when deleting an > object? Or he may have implemented some more complex mechanisms to enable > him to work correctly > [image: a5cbb602c2825e1357b98b6773976d9.png] > 在2024年5月11日星期六 UTC+8 15:35:36<Justin Israel> 写道: > >> I don't know enough about the needs of your code to comment on what is >> the right choice. But if you are the one deleting the node and you already >> have the fullpath then it feels like you could set the field to None, and >> then retrieve the MObject again later when you need it (if None, retrieve). >> Otherwise if you hang onto it, it might still keep the object alive and >> hidden from the graph for the undo queue, but it might not be valid for you >> to do anything with. You could look at MobjectHandle if you need to hold >> onto a ref beyond it being deleted and to check if your MObject is valid or >> not: >> https://download.autodesk.com/us/maya/docs/maya85/API/MObjectHandle.html >> >> >> On Sat, May 11, 2024, 7:24 PM Kangd dan <[email protected]> wrote: >> >>> Thank you Justin!! I'm not very familiar with the Maya API yet, so I >>> might need some time to read through the content in the link! I have a >>> question: >>> Can I always keep the memory address of the MObject? When I delete an >>> object, I comment out this line of code: # self._apiNode = None. I find >>> that by doing this, when I delete an object and then undo, I can still >>> ensure that it is accessible >>> >>> 在2024年5月11日星期六 UTC+8 14:38:08<Justin Israel> 写道: >>> >>> Well you clear the variable yourself during the delete operation. So the >>> Maya undo mechanism has no way to restore the private fields in your Python >>> instance. >>> So you need to clear the field at all, during the delete? Or can you >>> re-query the object from the fullpath as-needed? >>> >>> There are more advanced hooks into undo/redo using the MpxCommand >>> implementation: >>> https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=Maya_SDK_Command_plug_ins_UndoableCommands_html >>> >>> On Sat, May 11, 2024, 6:30 PM Kangd dan <[email protected]> wrote: >>> >>> Hello everyone, I've been trying to write a lightweight Maya Python >>> wrapper recently, using the Open Maya API to dynamically query the unique >>> names of objects, and cmds for setting commands. However, I've encountered >>> a problem. When I delete an object and also set its MObject path to None, >>> if I want to undo the deletion, cmds can indeed correctly undo it. But at >>> this point, the MObject path has already been set to None, and since it was >>> set directly through Python, it doesn't support undo. I would like to ask >>> whether it is possible to retain the MObject's memory path when deleting >>> the object? This way, when I delete an object and undo the deletion, I can >>> still use that path >>> [image: 1715408354509.jpg] >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Python Programming for Autodesk Maya" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/python_inside_maya/b56166dc-9576-4f76-99db-c09e2822987dn%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/python_inside_maya/b56166dc-9576-4f76-99db-c09e2822987dn%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Python Programming for Autodesk Maya" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> >> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/python_inside_maya/87933431-bc16-4319-865b-9736280307d4n%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/python_inside_maya/87933431-bc16-4319-865b-9736280307d4n%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/39cf4384-602f-44e3-8ba0-51ed7f49cbbbn%40googlegroups.com.
