Print Number of Points, Curves and Shapes

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
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Print Number of Points, Curves and Shapes

Post by Rasheed »

I have written my first ever layer script and it works!

The script prints the number of points, curves and shapes in the layer in which it is embedded. Why is this script useful? Well, if you have made mistakes (or if you are revising Moho files from others), you can use this layer script for debugging.

Nothing fancy, nothing elaborate, just had a lot of fun creating it. And it is Public Domain, so you can change it however you like, as long as you keep the credits intact and add your name to it as a co-creator.

Here is the file for download as a ZIP archive (642 bytes):
PrintNumberOfPointsCurvesAndShapes.lua.zip

And I have very little programming experience, so I guess if I can do this, many more people could do this as well.

Because the script is so small, I give you the code in this message:
PrintNumberOfPointsCurvesAndShapes.lua wrote:

Code: Select all

-- ******************************************************************************
-- Print the Number of Points, Curves and Shapes in a layer
-- Layer Script to help you debug your vector layer
-- by Rene van Belzen
--
-- Public Domain 2006
-- ******************************************************************************
function LayerScript(moho)
	local layerName = moho.layer:Name()

	if (NUM_POINTS == nil) then
		NUM_POINTS = {}
		NUM_POINTS[layerName] = 0
	end

	if (NUM_CURVES == nil) then
		NUM_CURVES = {}
		NUM_CURVES[layerName] = 0
	end

	if (NUM_SHAPES == nil) then
		NUM_SHAPES = {}
		NUM_SHAPES[layerName] = 0
	end

	local mesh = moho:Mesh()
	if moho.frame == 0 and mesh ~= nil then
		local numPoints = mesh:CountPoints()
		local numCurves = mesh:CountCurves()
		local numShapes = mesh:CountShapes()

		if numPoints ~= NUM_POINTS[layerName] or numCurves ~= NUM_CURVES[layerName] or numShapes ~= NUM_SHAPES[layerName] then
			print("There are now "..numPoints.." points, "..numCurves.." curves and "..numShapes.." shapes in layer ""..layerName.."".")
			NUM_POINTS[layerName] = numPoints
			NUM_CURVES[layerName] = numCurves
			NUM_SHAPES[layerName] = numShapes
		end
	end
end
Neat and simple, isn't it?

You embed it into your Moho layer by double clicking the layer in the Layer Window, checking the Embedded script file checkbox in the Layer Settings window that appears, select the script file in the file dialogue and click on Open to select and click on OK to close the Layer Settings window.

The layer script only works on vector layers and in frame zero.

Have fun using it!

Peace,
René.
User avatar
Rai López
Posts: 2259
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

VERY WELL!!! :D ...And what an envy! Seems that now everybody can write scripts but I :cry: ...WELL! Now an idea, that is the only one thing that I can offer :roll: ...See you this:

http://www.lostmarble.com/forum/viewtop ... ght=points

So... what about joining this two stupids? (jaja) scripts in only one??? I think that adding a button to the How Many Points 7feet's tool to can call the printed results for a complete information of Rasheed script (only when you want), we could have a more very useful, practice and (maybe) not "so stupid" info script! ;)

PS: By the way... THANKS! :D (and CONGRATULATIONS)
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

Well Ramón, you'll have to ask 7Feet (Brian) to extend his script, so that you can have an overview displayed in a separate window of the number of points, curves and shapes per layer and in the whole Moho document. It is just beyond my abilities at this moment. And maybe it should list only the statistics you want, like the number of shapes for a certain layer, or the number of points of each shape in a layer, or whatever you want. And not only properties of vector layers, but all other layers as well, as well as general statistics of the media files.
User avatar
7feet
Posts: 840
Joined: Wed Aug 04, 2004 5:45 am
Location: L.I., New Yawk.
Contact:

Post by 7feet »

I'll slap 'em together. I saw a few minutes ago the output from that script on a screenshot you had posted in another thread, and I thought that was pretty cool. Shouldn't take much, I'll try to cram that in to my suddenly busy schedule. It's great not being bored!

And good job there, Rasheed. Handy. And the more scripters here the merrier. It was lonely at first...

EDIT- yeah, I'll whip this out. It's always the user interface stuff that I dread (I blow it up real good, pretty often) but this should be straightforward. I'll say by tomorrow night, I will.
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

I read somewhere that writing good code is a painstaking process. Sometimes you get stuck and have to retrace your steps to an earlier version (so, keeping several versions while developing your code is essential). Sound logical reasoning and keeping your code tidy and readable seem essential. And it seems that roughly 90% of coding is about maintaining code that was written by someone else, or by yourself months or even years ago.

About building that GUI stuff. It might be handy to have some visual toolkit for that, like many programming languages have nowadays. Perhaps someone has already made a similar tool for another application that is Lua scriptable. I will look into that. If such a kit exists and it can be modified to work with Moho, it would be a real time saver.
User avatar
Rai López
Posts: 2259
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

Rasheed wrote:If such a kit exists and it can be modified to work with Moho, it would be a real time saver.
YEAH! (and HI! :) ) I always have thought that some little app or interface to help in this work and make it a little more "understandable" it'd be a GREAT favour to improve the process and make it a little more friendly too :) so... GOOD LUCK IN YOUR SEARCH!
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

It may take a little while, Ramón, because Moho's GUI is very proprietary.
User avatar
Rai López
Posts: 2259
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

Well, I understand :) ...but anyway: THANK YOU very much for all your lately scripting initiatives! :D
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

As a backup plan, if no suitable visual toolkit coud be found, I think the Gimp Toolkit (GTK+) is a good framework to create a kind of Moho scripting studio. Such an app would make it possible for people with little programming experience to create their own scripts, so more animators could benefit from Moho scripting and experienced script writers could do rapid application development (RAD) and fine tune the code by hand.

I will keep looking on the Lua user project page to see if one of the app makers has made an open source application which could be modified for Moho scripting.

An additional solution could be to write a good tutorial on Moho scripting, something which is lacking at the moment (just as a more comprehensive Moho animation tutorial is missing). The current version of the scripting documentation is rather basic IMHO and not suited for newbies.
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

Rasheed wrote:As a backup plan, if no suitable visual toolkit coud be found, I think the Gimp Toolkit (GTK+) is a good framework to create a kind of Moho scripting studio.
Strike that. I couldn't get it to install, although I added a ton of additional Unix libraries to my system. The problem was that Pango couldn't find my "libXm.3.dylib" file (whatever that may be). I tried some other stuff, but that needed OS X Tiger to work (I have an earlier version), and gave up after five hours of Googling and fruitless installing.

While I was doing that, I read that GUI programming is indeed very difficult and many programmers have found Lua to be more than capable to solve their GUI programming needs.

Perhaps I'm looking at this in the wrong way. Why try to find a C/C++ toolkit (there are plenty of those around) when C/C++ programming is unnecessarily difficult (at least, I never succeeded in writing a program more complex than HelloWorld.cpp, because the C++ lingo just didn't stick in my memory enough)? Perhaps I should try a Python GUI, because Python is just as easy to grasp as Lua. It has a limited number of easy to understand concepts and uses a sober coding style (without al the extra overhead—if you have ever tried to write a Java program, you know what I mean).

As I have experienced so often, I have had an idea here that not so many people seem to have had (or tried to follow up): writing a separate program to help me program a GUI for another program, that programs yet another program. Well, I will keep trying.
User avatar
bupaje
Posts: 1175
Joined: Fri Nov 12, 2004 5:44 pm
Location: California
Contact:

Post by bupaje »

Rasheed I know nothing -so don't want to send you on a wild goose chase- but came across this which seems to relate to a visual toolkit for Lua -I may be wrong. :)

http://visualwx.altervista.org/
[url=http://burtabreu.animationblogspot.com:2gityfdw]My AnimationBlogSpot[/url:2gityfdw]
User avatar
Rai López
Posts: 2259
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

Hmmm... I neider know nothing, but... seems interesting, so... THANKS!!! :D I hope someone here knows how take advantadge of this discovery... :roll:
Last edited by Rai López on Wed Jan 25, 2006 1:23 pm, edited 1 time in total.
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

It is Windows only, so not so useful in combination with Moho.

My plans are as follows:
• Learn Lua and Python with Tkinter
• Learn GUI scripting for Moho
• Approach Moho animators to ask for their input, what they want this tool to be
• Write an alpha version and ask for script writers to test and help improve the toolkit
• Write a beta version and ask for non-script writers to test and give positive critique to improve the toolkit
• Write a first official release for the Moho community
• Keep improving the tookit, based on user input

So while I'm in the learning phase, there will be no toolkit. I want this toolkit to be easy to learn and easy to maintain, and that asking a lot of my talents for a first major programming task. I believe someone has already said: "If it is easy to do, it isn't worth bothering about." So with that in mind, this project should be very interesting indeed.

But if I find a similar project that is already finished (or nearing completion) and it is easy to modify for use with Moho, I'm not at all afraid to have a look at it and see if it's better than what I have come up with.

The only thing I ever wanted to achieve with this project is to help animators to create better animations because they will have better tools to do so. And those tools could be made (or modified) specifically for an animation project, perhaps to shorten the production time, or to create innovative effects that weren't possible before.
Post Reply