I can not use undo.

This is my script.

bip_ctr=$selection[1].controller
biped.createCopyCollection bip_ctr "__Delete"
copycol=biped.getcopycollection bip_ctr (biped.numCopyCollections bip_ctr)

ICP_MXBipedCopy=biped.copyBipPosture bip_ctr copycol ($selection as array) #snapAuto

biped.pasteBipPosture bip_ctr ICP_MXBipedCopy true #pstdefault false false false false

for i=1 to biped.numCopyCollections bip_ctr
do
(
c=biped.getCopyCollection bip_ctr i
if c.name=="__Delete"
do
(
biped.deleteCopyCollection bip_ctr i
exit
)
)

This works correctly.
Paste the selected biped body part in the opposite.
This is available even without Copycollections.

But I can not undo this
Regardless of where I put the undo code, if I try undo, 3ds max will fail with an error.
What should I do?