The ScriptInterface class is a script's way of interacting with the Moho application itself. When a script is invoked (by a mouse click, a key press, or a menu command), it is provided with an object called "moho" - this object is an instance of the ScriptInterface class.
Member Variables
fFrame (int)
The current time in the timeline.
fDoc (MohoDoc)
The current document object open in Moho.
fLayer (MohoLayer)
The currently selected layer in the Layers window.
fView (MohoView)
The editing view.
fGridOn (bool)
True if the grid is turned on in the editing view, otherwise false.
fGridSize (float)
The size of one grid unit.
Member Functions
void Click()
Play a little clicking sound. This is currently used as feedback for welding operations.
Return value: none
void SetCurFrame(frame)
Set the current time.
Return value: none
frame (int): frame number
void UpdateUI()
Force the user interface to redraw itself. This is in case certain elements have become disabled or enabled due to the changing state of the Moho document.
Return value: none
void NewKeyframe(channel)
Tells the timeline window to display a new keyframe in the specified animation channel. This does not actually add the keyframe - you need to do that separately - it just displays the keyframe in the timeline. See the animation channel constants.
Return value: none
channel (int): which animation channel
void UpdateSelectedChannels()
Updates the display of "selected" channels in the timeline. (Like selected points, selected bone, selected shape, etc.) Use this function if your script changes which object(s) are selected.
Return value: none
void SetSelLayer(layer)
Changes which layer is selected in the Layers window.
Return value: none
layer (MohoLayer): new selected layer
MohoLayer CreateNewLayer(layerType)
Creates a new layer, inserts it directly above the currently selected layer in the Layers window, and makes it the selected layer.
Return value (MohoLayer): the new layer
layerType (int): a layer type code
MohoLayer DuplicateLayer(layer)
Duplicates the given layer, placing the new copy above the old one and making it the selected layer.
Return value (MohoLayer): the new layer
layer (MohoLayer): an existing layer to duplicate
void PlaceLayerInGroup(child, group, top)
Moves a layer into a group.
Return value: none
child (MohoLayer): the layer to move
group (MohoLayer): the group layer to put it in
top (bool): true to place it at the top of the group, false to place it at the bottom
void PlaceLayerBehindAnother(moveLayer, behindThis)
Moves one layer behind (or below) another in the layer ordering.
Return value: none
moveLayer (MohoLayer): layer to move
behindThis (MohoLayer): layer to place it behind
ImageLayer LayerAsImage(layer)
Converts a generic layer object into an image layer. The layer is not modified - this is equivalent to "casting" from one type of pointer to another in C. Some functions return a generic layer object, even if the layer is really an image layer - use this function if you need to work with ImageLayer-specific functions.
Return value (ImageLayer): an ImageLayer object
layer (MohoLayer): the layer to cast
GroupLayer LayerAsGroup(layer)
Converts a generic layer object into a group layer.
Return value (GroupLayer): a GroupLayer object
layer (MohoLayer): the layer to cast
SwitchLayer LayerAsSwitch(layer)
Converts a generic layer object into a switch layer.
Return value (SwitchLayer): a SwitchLayer object
layer (MohoLayer): the layer to cast
ParticleLayer LayerAsParticle(layer)
Converts a generic layer object into a particle layer.
Return value (ParticleLayer): a ParticleLayer object
layer (MohoLayer): the layer to cast
Mesh3DLayer LayerAs3D(layer)
Converts a generic layer object into a 3D layer.
Return value (Mesh3DLayer): a Mesh3DLayer object
layer (MohoLayer): the layer to cast
M_Mesh Mesh()
Returns the 2D mesh associated with the currently active layer. If the active layer is not a vector layer, then this function returns nil.
Return value (M_Mesh): a 2D mesh object
void SnapToGrid(v)
Takes a vector position and "snaps" it to the nearest grid intersection.
Return value: none
v (LM_Vector2): the vector to "snap"
void AddPointKeyframe(frame)
Adds a point motion keyframe to all the currently selected vector points.
Return value: none
frame (int): frame number
int CreateShape(filled, frame, checkForBadShapes)
Creates a shape based on the currently selected vector points. Not all shapes are "legal" (for example, non-closed fill shapes), so if this function fails it will return -1.
Return value (int): id number of the new shape
filled (bool): true to create a filled shape, false to create an outline only
frame (int): frame number to create the shape at
checkForBadShapes (bool): true to first do extra testing for "bad" or illegal shapes
float NewShapeLineWidth()
Returns what the line width would be for a new shape. This is based on the user settings in the Style window.
Return value (float): line width for new shapes
void InsertText(text, font, groupTogether, centerH, lineOffset)
Creates a new text object in the currently active vector layer. See the FillInFontList function below for information on how to get a list of the available fonts.
Return value: none
text (string): the text to create
font (string): the name of the font to use
groupTogether (bool): true to group all characters as a single fill shape, false to fill them separately
centerH (bool): true to center the text horizontally, false to left-justify
lineOffset (int): how many lines down to offset the text (used to create multi-line text objects)
M_Skeleton Skeleton()
Returns the skeleton object associated with the current layer. If the current layer is not a bone layer, this function returns nil.
Return value (M_Skeleton): a skeleton object
M_Skeleton ParentSkeleton()
Returns the skeleton object associated with the parent layer of the current layer. If there is no parent layer, or the parent layer is not a bone layer, this function returns nil.
Return value (M_Skeleton): a skeleton object
void UpdateBonePointSelection()
Selects the points that are bound to the currently selected bone.
Return value: none
M_Mesh3D Mesh3D()
Returns the 3D mesh object associated with the current layer. If the current layer is not a 3D layer, this function returns nil.
Return value (M_Mesh3D): a 3D mesh object
float BeginAudioExtraction(path)
Begin extracting amplitude data from an audio file.
Return value (float): the duration (in seconds) of the audio file
path (string): pathname to the audio file
float GetAudioAmplitude(startTime, duration)
Get the average audio amplitude of a section of an audio file. Audio amplitude will be normalized from between 0.0 and 1.0.
Return value (float): average amplitude
startTime (float): the start time (in seconds) of the section to analyze
duration (float): the duration (in seconds) of the section to analyze
float GetAudioRMSAmplitude(startTime, duration)
Get the RMS audio amplitude of a section of an audio file. Audio amplitude will be normalized from between 0.0 and 1.0.
Return value (float): RMS amplitude
startTime (float): the start time (in seconds) of the section to analyze
duration (float): the duration (in seconds) of the section to analyze
float GetAudioMaxAmplitude(startTime, duration)
Get the maximum audio amplitude of a section of an audio file. Audio amplitude will be normalized from between 0.0 and 1.0.
Return value (float): maximum amplitude
startTime (float): the start time (in seconds) of the section to analyze
duration (float): the duration (in seconds) of the section to analyze
void EndAudioExtraction()
Call this function when you're finished extracting audio data from a sound file.
Return value: none
float PixelToDoc(pixel)
When the user specifies things like line width, blur radius, and shadow offset in Moho, they enter a value in pixels. However, behind the scenes, these values are stored in "document coordinates". This allows an animation to be rendered at different resolutions while still looking correct. This function will convert between pixels and document coordinates.
Return value (float): the equivalent distance in document coordinates
pixel (int): a distance in pixels
int DocToPixel(doc)
When the user specifies things like line width, blur radius, and shadow offset in Moho, they enter a value in pixels. However, behind the scenes, these values are stored in "document coordinates". This allows an animation to be rendered at different resolutions while still looking correct. This function will convert between document coordinates and pixels.
Return value (int): the equivalent distance in pixels
doc (float): a distance in document coordinates
int CountPoints()
Returns the number of points in the current vector layer.
Return value (int): number of points
int CountSelectedPoints()
Returns the number of selected points in the current vector layer.
Return value (int): number of selected points
int CountCurves()
Returns the number of curves in the current vector layer.
Return value (int): number of curves
int CountEdges()
Returns the number of edges in the current vector layer. (An edge is one segment of a curve between two control points.)
Return value (int): number of edges
int CountSelectedEdges()
Returns the number of selected edges in the current vector layer. (An edge is considered selected if both points at the ends of the edge are selected.)
Return value (int): number of selected edges
int CountShapes()
Returns the number of shapes in the current vector layer.
Return value (int): number of shapes
int CountSelectedShapes()
Returns the number of selected shapes in the current vector layer.
Return value (int): number of selected shapes
int CountBones()
Returns the number of bones in the current bone layer.
Return value (int): number of bones
int CountSelectedBones()
Returns the number of selected bones in the current bone layer.
Return value (int): number of selected bones
void FillInFontList(list)
Fills in an LM_TextList interface object with the list of available fonts on the system.
Return value: none
list (LM_TextList): a text list GUI object to fill in
LM_Vector3 NoiseVector(pos, amp, freq)
Generates a semi-random vector.
Return value (LM_Vector3): the random vector
pos (LM_Vector3): location to generate the random vector at (nearby locations will have similar "random" vectors)
amp (float): the average amplitude of the generated vector
freq (float): the frequency of the noise
void ImportEPS(path)
Import an EPS or Adobe Illustrator file into Moho, creating a new vector layer to hold it.
Return value: none
path (string): pathname to the imported file