0% found this document useful (0 votes)
52 views3 pages

Moho Scripting by Silas.2d

Moho Scripting by Silas.2d

Uploaded by

Silas.2d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views3 pages

Moho Scripting by Silas.2d

Moho Scripting by Silas.2d

Uploaded by

Silas.2d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Introduction

The scripting interface in Moho (Anime Studio) is divided into three "modules":

LM is the lowest-level module, and includes very basic objects like vectors and colors.

LM.GUI is a user interface module that is built on top of Moho's cross-platform user
interface library. Scripts can use the user interface widgets in this module to build dialog
boxes, and to set up custom interfaces for toolbar buttons.

MOHO is the module that is a direct interface into Moho itself. The objects and functions in
the MOHO module allow scripts to create and manipulate layers, vector artwork, bone
systems, and more.

Getting started with scripting

Moho scripts are written in Lua. This describes the basics of Lua: Programming in Lua

If you're already familiar with block-structured languages then you shouldn't have any real
problems with Lua.

You will find many descriptions of constants (e.g. Channel Codes, Layer Types) in this
website. They include the identifier and its value. Note that the value can (and, indeed, on
occasion does) change between different Moho versions. When writing code, always use
the identifier and never use the value. (The value is provided only to help decipher the
contents of moho data files.)

A word about Global variables.


-------------------------------------------------
Rule 1 in the Moho context: if you MUST use a global, then prefix it with some unique to
you identifier. E.g. Moho uses LM_; other examples are HS_ , syn_, SZ_, AE_ ... It's best
to use local variables by default except where necessary -- such as all your script functions
that Moho expects to find (e.g. function HS_Myscript:Name() ).
A cautionary word about creating Moho data objects.
-------------------------------------------------------------------------------------
Most of the Moho data objects will be of Lua type "userdata". e.g. as shown below the
code
local vec = LM.Vector2:new_local()
creates "vec" as an object of class LM_Vector2
Even though the Moho data type includes the word 'local' it is vital to add the Lua 'local'
tag.
if you write:
vec = LM.Vector2:new_local()
(i.e. not expressly defining vec as a local Lua item) this will create a Global variable vec

Interfacing with Moho

You're already in the right place for understanding how to get Moho and your scripts
talking to each other...

A good place to start is to take a quick look (don't try to learn them!!) at the "core" classes
in
Moho : AnimChannel, M_Bone, M_Curve, M_Mesh, M_Point, M_Shape, M_Skeleton, Moh
oDoc, MohoLayer, ScriptInterface and get a feel for what's in them and how they fit
together.

The "mesh" family

Here's a summary of the mesh / point / shape / curve relationships

>> Mesh "holds" all the points. points are numbered in the mesh from 0 ...
mesh:CountPoints()-1

>> Mesh also holds "curves" - which are ordered lists of points. Curves are numbered form
0 ... mesh:CountCurves()-1

>> A path (a curve) is made up of points. Points are ALSO numbered in a curve from 0 ...
curve:CountPoints()-1 Note that these numbers are different -- e.g. Curve(1): Point(3)
might be Mesh:Point(44)

>> A curve is made up of segments. They are numbered 0 ... curve:CountSegments() -1.
Generally the start point of segment (x) is point in curve (x). If the curve is closed (i.e. a
loop) segments = points; if it's not, there's one more point than segments.

>> A shape has edges; they are numbered 0 ... Shape:CountEdges()-1. An edge is a
segment of a curve. One segment can be in many shapes.
Writing your script

This scripting documentation has a Script Structure page that sets out the fundamental
elements for menu, tool and layer scripts. There's also template generator accessible from
the "tools" button.

If you fancy trying something before starting on a "serious" script, you might like to set
yourself a simple challenge - e.g. draw a circle - centre is mouse click, radius is where the
"drag" ends. (You could use the LM_Shape tool as a crib sheet for that if you get stuck.)
Then build on that to get the circle to glide across the screen ... etc

A code snippet

Most Moho data objects don't need to be explicitly created -- calling something that
"returns" a class gives you the userdata object: (e.g.) an M_Point class is returned by
M_Mesh:Point(n) so:

local x = 5 -- assign a value

local vec = LM.Vector2:new_local() -- LM_Vector2

local mesh = moho:Mesh() -- ScriptInterface:Mesh

local pt = mesh:Point(x) -- M_Mesh:Point

vec:Set(pt.fPos) -- M_Point

sets vec to be the position of point "5"

You might also like