Deactivate an action?

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
strider2000
Posts: 506
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Deactivate an action?

Post by strider2000 »

Is there a correct way to programmatically return to the --- Mainline ---. I know how to activate an action. I tried Activating "Mainline" and "--- Mainline ---" but that didn't seem to work. It does seem that if I create a junk action and then delete it then I accomplish what I want, but that really doesn't seem to be the elegant approach :o
Stan
Posts: 199
Joined: Sun Apr 19, 2009 3:22 pm

Re: Deactivate an action?

Post by Stan »

If you don't care for older versions (earlier than 10.0), then you can just use this:

Code: Select all

moho.document:SetCurrentDocAction(nil)
However, if you do care for older versions, here is the correct way to do it (complete button-script):

Code: Select all

-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************

ScriptName = "SZ_ActivateMainline"

-- **************************************************
-- General information about this script
-- **************************************************

SZ_ActivateMainline = {}

function SZ_ActivateMainline:Name()
	return "Activate Mainline"
end

function SZ_ActivateMainline:Version()
	return "1.0"
end

function SZ_ActivateMainline:Description()
	return "Quit edit action and go to mainline"
end

function SZ_ActivateMainline:Creator()
	return "Stan aka Vodka"
end

function SZ_ActivateMainline:UILabel()
	return "Activate Mainline"
end

-- **************************************************
-- The guts of this script
-- **************************************************

function SZ_ActivateMainline:IsEnabled(moho)
	if moho.layer:CurrentAction() ~= "" then
		return true
	end
	return false
end

function SZ_ActivateMainline:IsRelevant(moho)
	return true
end

function SZ_ActivateMainline:Run(moho)
	if moho.layer:CurrentAction() ~= "" then
		local version = 9.0
		if moho.AppVersion ~= nil then
			local sVersion = string.gsub(moho:AppVersion(), "^(%d+)(%.%d+)(%..+)", "%1%2")
			version = tonumber(sVersion)
			-- print(sVersion)
		end
		if version >= 10.0 then
			moho.document:SetCurrentDocAction(nil)
		end
		moho.layer:ActivateAction(nil)
		moho.layer:UpdateCurFrame()
		moho:UpdateUI()
	end
end
And here's the icon: Image
________________________________________________________________________
https://mohoscripting.com/ - Unofficial Moho Lua scripting documentation
https://mohoscripts.com/ - The best place to publish and download scripts for Moho
User avatar
strider2000
Posts: 506
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Re: Deactivate an action?

Post by strider2000 »

Much thanks Stan :D Very much appreciated. 10+ is good for me.
Post Reply