Deactivate an action?

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

Moderators: Fahim, Distinct Sun, Víctor Paredes, erey, Belgarath, slowtiger

Post Reply
User avatar
strider2000
Posts: 443
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Deactivate an action?

Post by strider2000 » Tue Dec 22, 2015 9:31 pm

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
My new website (just getting started) | M1 Characters for Moho
Stan
Posts: 121
Joined: Sun Apr 19, 2009 3:22 pm
Contact:

Re: Deactivate an action?

Post by Stan » Tue Dec 22, 2015 11:17 pm

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
________________________________________________________________________
http://mohoscripting.com/ - Unofficial Moho (Anime Studio) Lua Scripting Documentation
http://2danimator.ru/ - Russian Anime Studio Forum
User avatar
strider2000
Posts: 443
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Re: Deactivate an action?

Post by strider2000 » Wed Dec 23, 2015 12:43 am

Much thanks Stan :D Very much appreciated. 10+ is good for me.
My new website (just getting started) | M1 Characters for Moho
Post Reply