Problems that cannot be undone after using scripts

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
570295535
Posts: 12
Joined: Sat Feb 04, 2023 9:32 am

Problems that cannot be undone after using scripts

Post 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
User avatar
hayasidist
Posts: 3526
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Problems that cannot be undone after using scripts

Post 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.
User avatar
570295535
Posts: 12
Joined: Sat Feb 04, 2023 9:32 am

Re: Problems that cannot be undone after using scripts

Post by 570295535 »

Code: Select all

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