I'm not sure what you meant by "shape names". AFAIK a shape doesn't have a name, only a reference (which is sometime called the
shape ID). Although there are no shape names, one can define point groups, which have names. Is this perhaps what you meant?
One refers to shapes (and all other moho objects) via a structure called
userdata. Userdata is in essence an interface with the C++ programming code of Anime Studio.
In vector layers there is a mesh object available. The vector layer automatically inherits the member function Mesh(). You refer to that member function with
moho:Mesh(). This means "run the Mesh function of this layer".
moho here simply means "this layer". The Mesh() member function returns the reference to ("address" of) the mesh object in the vector layer. You capture this mesh object in Lua as follows:
The local variable
mesh now contains the mesh object of the scripted layer (the layer containing the layer script). If there is no mesh available (e.g. in a group layer),
moho:Mesh() returns a
nil value (meaning: "does not exist").
The mesh object itself has also function members, such as:
- CountShapes() -- returns the number of shapes in the mesh (an integer value)
- Shape(n) -- returns the reference ("address") to the n-th shape object in the mesh (beginning counting from zero)
- CountGroups() -- returns the number of points groups in the mesh (an integer value)
- Group(n) -- returns the reference ("address") to the n-th point group object in the mesh
Each point group object has member functions as well, such as:
- Name() -- returns the name of the point group (a string value)
Here is some sample code to explain.
Code: Select all
function LayerScript(moho)
local mesh = moho:Mesh() -- the current scripted layer's mesh
-- if there is no mesh available, exit the script layer
if ( mesh == nil ) then
return false
end
local shapes = {} -- array to hold the shapes
local groups = {} -- array to hold the point groups
-- and their names
local shapeCount = mesh:CountShapes() -- count the shapes
if (shapeCount > 0 ) then
for i=0, shapeCount - 1 do
shapes[i] = mesh:Shape(i) -- read shape into array
end
end
local groupCount = mesh:CountGroups() -- count the point groups
if ( groupCount > 0 ) then
for i=0, groupCount - 1 do
groups[i] = mesh:Group(i) -- read point groups into array
groups[i].name = groups[i]:Name() -- read PG name into array
print (i .. ': ' .. groups[i].name ) -- print it
end
end
end
I hope the earlier explanation is clear enough to demystify the Lua code. I have any questions, be sure sure to ask them, and I will see if I can answer them.
And if you meant something completely different than I described here, feel free to point that out as well.