Thank you, Marcus! This has been incredibly helpful to me. I'm not very 
familiar with the OpenMaya API yet, but I will carefully review your links 
and code tomorrow!! Thanks again, and have a great day!

在2024年5月12日星期日 UTC+8 00:28:02<Marcus Ottosson> 写道:

> Ooo more wrappers. :) I’ve got one too you could reference for things like 
> undo.
>
>    - https://github.com/mottosso/cmdx 
>
> There’s also omx, along with a comparison of the two I made not too long 
> ago.
>
>    - https://learn.ragdolldynamics.com/blog/20240101_omx_vs_cmdx 
>
> For a UUID, Maya already has you covered. The MObjectHandle has a .hexCode 
> you can use that you can optionally convert to a hex code. It will survive 
> undo/redo, as objects remain in memory for as long as they remain in the 
> undo queue.
> handle = om.MObjectHandle(mobject) hsh = handle.hashCode() hx = "%x" % 
> hsh 
>    
>    - See this example 
>    
> <https://github.com/mottosso/cmdx/blob/522fbdaa9c4d1ea82a6f3725e7f30f661673edac/cmdx.py#L457C1-L459C24>
>  
>
> For undo, the approach that both cmdx and omx takes is to perform all 
> changes via an MDGModifier and wrap it with a MPxCommand. That way, it will 
> take its place alongside all other undoable things in Maya.
> import cmdx with cmdx.DagModifier() as mod: mod.set_attr(attr, value) 
>    
>    - See here for implementation 
>    
> <https://github.com/mottosso/cmdx/blob/522fbdaa9c4d1ea82a6f3725e7f30f661673edac/cmdx.py#L5845>
>  
>    - See here for examples 
>    
> <https://github.com/ragdolldynamics/ragdoll-maya/blob/6c8728b7d1c3ac78fc28fe2e90250b68ade5f650/ragdoll/commands.py#L61>
>  
>
> And here’s a standalone sandbox project for undo/redo with the API in 
> Maya, this is the one embedded into cmdx.
>
>    - https://github.com/mottosso/apiundo 
>
> Hope it helps, and good luck! :)
> ​
> On Saturday 11 May 2024 at 17:15:03 UTC+1 aa1518...@gmail.com wrote:
>
>> 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 <aa1518...@gmail.com> 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 <aa1518...@gmail.com> 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 python_inside_m...@googlegroups.com.
>>>>> 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 python_inside_m...@googlegroups.com.
>>>>>
>>>> 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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/f13b0fe0-2e60-4078-8ee9-fe2ff2e0e23en%40googlegroups.com.

Reply via email to