Hi Peter,
first of all don't get into a nervous vicious circle.
ScriptName is a variable that must be defined with exactly the same name of the script you're writing. It probably would be used by the scriptinterface to index the scripts available or similar. People usually have a naming scheme where the two capital leters of the script is the initials of the creators ("GE" in my case)
Regarding to the other questions you're spawning around the forum I would try to give you a quick overview of how does it work:
There are three kind of scripts: Tools, Menu scripts and embedded scripts.
Tools: I've not looked or tried to write any so I just can point to the existing ones. It does perform a continous action until its state is left by selecting other tool. There is always a tool script running when the program is idle.
Menu scripts are one action scripts and just perform an action once it is called. Menu scripts has a function that has to be defined that checks if it is enabled.
Code: Select all
function GE_FreezePoints:IsEnabled(moho)
local mesh = moho:Mesh()
if (mesh == nil) then return false end
-- if (moho:CountSelectedPoints() == 0) then return false end
end
You define that function that is called by the script interface using the moho variable. I think you can call it whatever you want but the argument of that function is a moho object.
The rest of functions hae the same structure: you define it and it is called with a moho object (or better a moho class instance) as argument. From the moho clas instance you extract whatever you need.
Code: Select all
-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************
ScriptName = "GE_FreezePoints"
-- **************************************************
-- General information about this script
--Use together with freezer.lua embedded script
-- **************************************************
GE_FreezePoints = {}
GE_FreezePoints.Table = {}
function GE_FreezePoints:Name()
return "Freeze Selected Points"
end
function GE_FreezePoints:Version()
return "1.0"
end
function GE_FreezePoints:Description()
return "Freezes the selected points and release the non selected points if were previously frozen."
end
function GE_FreezePoints:Creator()
return "Genete"
end
function GE_FreezePoints:UILabel()
return("Freeze Selected Points and Release non Selected")
end
-- **************************************************
-- The guts of this script
-- **************************************************
function GE_FreezePoints:IsEnabled(moho)
local mesh = moho:Mesh()
if (mesh == nil) then return false end
-- if (moho:CountSelectedPoints() == 0) then return false end
end
function GE_FreezePoints:Run(moho)
local mesh = moho:Mesh()
if (mesh == nil) then
return
end
lname = moho.layer
if (self.Table[lname] == nil) then
self.Table[lname]= {}
end
for i = 0, mesh:CountPoints() - 1 do
local point = mesh:Point(i)
if (point.fSelected == true) then
-- print ("point " .. i .. " is selected")
if (self.Table[lname][i] == nil) then
self.Table[lname][i] = {}
end
self.Table[lname][i].x = point.fPos.x
self.Table[lname][i].y = point.fPos.y
end
if (point.fSelected == false) then
-- print ("point " .. i .. " is not selected")
if (self.Table[lname][i] ~= nil) then
self.Table[lname][i] = nil
end
end
end
--
for k in self.Table do
for i in self.Table[k] do
node = self.Table[k][i]
if (node ~= nil) then
print ("Point " .. i .. " from layer: " .. k:Name() .. " is in the table")
print ("X = " .. node.x)
print ("Y = " .. node.y)
else
print ("point " .. i .. " is NOT in the table")
end
end
end
end
Each menu script has a ::Run function that performs the magic. That's all.
As you can see with the moho instance you get lots of things: current selected layer, camera object, etc.
The thing is that you have to review all the damn moho scripting documentation so see what can be stracted from the moho class, what can be done and what is the interface to create layers, select points, add bones, change shape's style, etc.
Regarding to embedded scripts the situation is similar but the script is called everytime the time cursor is moved and the environment of the script is the laeyr where it is embedded.
Code: Select all
-- *******************************************
-- Embedded script for a vector layer
-- FREEZES THE COORDINATES OF THE POINTS THAT HAVE
-- BEEN FROZEN PREVIOUSLY WIHT THE GE_FREEZE_POINTS SCRIPT
-- Version: 1.0
-- Created By Genete
-- Usage in combination with ge_freeze_points.lua a menu script.
-- *******************************************
function LayerScript(moho)
local table = GE_FreezePoints.Table
if (table == nil) then
print ("table")
return
end
local layer = moho.layer
if (table[layer] == nil) then
print("table layer")
return
end
if (layer:LayerType() ~= MOHO.LT_VECTOR) then
print ("no vector")
return
end
mesh = moho:Mesh()
if (mesh == nil) then
print ("no mesh")
return
end
for i in table[layer] do
local x = table[layer][i].x
local y = table[layer][i].y
if (i > mesh:CountPoints()-1) then
table[layer][i] = nil
return
end
mesh:Point(i).fPos:Set(x,y)
-- print ("point " .. i .. "position is " .. x .. y )
end
end
In this example, the GE_FreezePoints.Table is accesed by the enbedded script because it was defined as global variable in the other script.
Botton line: You will never get more help from SM or LM about documentation. For them it is a double edge knife. It is a feature, attracts people to use and buy the program and it is a open door for features that people could add and that cannot be sold later as scripts because they are free once published.
Be patience and you'll enjoy a lot AS. Remember that it is animation not coding. Just code what is needed if you want but don't get loose like many of us did without doing grat animations with the current features of AS.
-G