Undo Script Tool?

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
J. Baker
Posts: 1063
Joined: Wed Mar 23, 2005 7:22 pm
Location: USA
Contact:

Undo Script Tool?

Post by J. Baker »

Is there an "Undo Script" Tool for drawing tablets?
User avatar
Lukas
Posts: 1297
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Undo Script Tool?

Post by Lukas »

Not tested this, but you could try this. Save it as LK_Undo.lua in your tools folder. If it works you can also create a redo button next to it, just change all instances of 'undo' into 'redo'

Code: Select all

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

ScriptName = "LK_Undo"

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

LK_Undo = {}

function LK_Undo:Name()
	return "Undo"
end

function LK_Undo:Version()
	return "0.1"
end

function LK_Undo:Description()
	return "Undo"
end

function LK_Undo:Creator()
	return "Lukas Krepel, Frame Order"
end

function LK_Undo:UILabel()
	return "Undo"
end

function LK_Undo:IsEnabled(moho)
	return true
end

function LK_Undo:IsRelevant(moho)
	return true
end

function LK_Undo:ColorizeIcon(moho)
	return true
end


-- **************************************************
-- The guts of this script
-- **************************************************
function LK_Undo:Run(moho)
	moho.document:Undo()
end
Last edited by Lukas on Tue Aug 03, 2021 8:34 pm, edited 1 time in total.
User avatar
J. Baker
Posts: 1063
Joined: Wed Mar 23, 2005 7:22 pm
Location: USA
Contact:

Re: Undo Script Tool?

Post by J. Baker »

Thanks! I tried but it doesn't work. It shows an "unknown" icon in "Other" tools panel but when clicked, no response.
User avatar
Lukas
Posts: 1297
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Undo Script Tool?

Post by Lukas »

J. Baker wrote: Tue Aug 03, 2021 8:24 pm Thanks! I tried but it doesn't work. It shows an "unknown" icon in "Other" tools panel but when clicked, no response.
Ah I see

Code: Select all

ScriptName = "Undo"
should have been:

Code: Select all

ScriptName = "LK_Undo"
I updated the previous post, it should run now 🙂
User avatar
J. Baker
Posts: 1063
Joined: Wed Mar 23, 2005 7:22 pm
Location: USA
Contact:

Re: Undo Script Tool?

Post by J. Baker »

Thank you very much! :D
User avatar
Lukas
Posts: 1297
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Undo Script Tool?

Post by Lukas »

No problem!

You know what, here's both undo and redo with icons, I see how this would be useful for tablets:
User avatar
J. Baker
Posts: 1063
Joined: Wed Mar 23, 2005 7:22 pm
Location: USA
Contact:

Re: Undo Script Tool?

Post by J. Baker »

Here's a zip file with the LUA, PNG icons, Read Me, and Moho document...

http://www.posemotion.com/download/LK_Undo.zip
User avatar
J. Baker
Posts: 1063
Joined: Wed Mar 23, 2005 7:22 pm
Location: USA
Contact:

Re: Undo Script Tool?

Post by J. Baker »

That's funny! We were thinking the same thing. I made new icons though. :D
User avatar
Lukas
Posts: 1297
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Undo Script Tool?

Post by Lukas »

Ha 😉 nice
User avatar
J. Baker
Posts: 1063
Joined: Wed Mar 23, 2005 7:22 pm
Location: USA
Contact:

Re: Undo Script Tool?

Post by J. Baker »

I renamed the "Undo" files, so that the Undo icon shows before the Redo icon in Moho. It's "LK_1_Undo" now.
User avatar
Lukas
Posts: 1297
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Undo Script Tool?

Post by Lukas »

J. Baker wrote: Tue Aug 03, 2021 10:21 pm I renamed the "Undo" files, so that the Undo icon shows before the Redo icon in Moho. It's "LK_1_Undo" now.
Actually, you can quite easy edit the order the tools are shown in by editing the _tools_list.txt file in the tools folder. So you don't have to change the names to re-order them.

Also, you can have the icons be greyed out if there's nothing to undo/redo by changing the IsEnabled function to this:

Code: Select all

function LK_Undo:IsEnabled(moho)
	if moho.document:IsUndoable() then
		return true
	end
	return false
end
(I updated/reuploaded my .zip)
User avatar
J. Baker
Posts: 1063
Joined: Wed Mar 23, 2005 7:22 pm
Location: USA
Contact:

Re: Undo Script Tool?

Post by J. Baker »

Very nice! Thanks!
User avatar
SimplSam
Posts: 1048
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Undo Script Tool?

Post by SimplSam »

Lukas wrote: Thu Aug 05, 2021 8:25 am ... Actually, you can quite easy edit the order the tools are shown in by editing the _tools_list.txt file ...
The recommended way is to use the GUI: Edit > Preferences > Tool Layout (even though it is painful if you want to move a lot of stuff around!).
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
J. Baker
Posts: 1063
Joined: Wed Mar 23, 2005 7:22 pm
Location: USA
Contact:

Re: Undo Script Tool?

Post by J. Baker »

Interesting. Thanks!
Post Reply