Page 1 of 1

Problems that cannot be undone after using scripts

Posted: Thu Sep 21, 2023 4:23 pm
by 570295535
I am a novice and am currently learning to write scripts. After using my script, it cannot be undone. Please let me know where the problem lies. Thank you

Code: Select all

ScriptName = "gg0"
gg0 = {}
function gg0:Name()
	return "gg0"
end
function gg0:Version()
	return "1.0"
end
function gg0:Description()
	return "gg0"
end
function gg0:Creator()
	return "xsz"
end
function gg0:UILabel()
	return"gg0"
end

function gg0:Run(moho)
    local layer = moho:LayerAsBone(moho.layer)
    if layer == nil then
        print("Please select at least one bone")
        return
    end
    local frame = moho.frame + 1
    local skel = moho:Skeleton()
	for i=0, skel:CountBones()-1 do
		local bone = skel:Bone(i)
		if bone.fSelected then
			oldangle=bone.fAnimAngle:GetValue(0)
			bone.fAnimAngle:SetValue(frame, oldangle)
		end
	end
	moho:SetCurFrame(frame)
end

Re: Problems that cannot be undone after using scripts

Posted: Thu Sep 21, 2023 7:22 pm
by hayasidist
take a look at https://mohoscripting.com/methods/732


e.g.

Code: Select all

    moho.document:PrepUndo(moho.layer, true)
    moho.document:SetDirty()
-- and for more examples of how to use it and how to mark a document as "dirty" (i.e. has been modified and needs to be saved) just follow any of the links referenced in the description of the function.

Re: Problems that cannot be undone after using scripts

Posted: Fri Sep 22, 2023 1:09 am
by 570295535

Code: Select all

    moho.document:PrepUndo(moho.layer, true)
    moho.document:SetDirty()
Thank you very much. This has solved my problem.