Rudiger wrote:
I suspect you've got one too many ends. Since you got rid of the "if(dlog:DoModal() == LM... ...then" line you have to get rid of the corresponding "end" statement.
Rudiger, thank you very much!
Indeed, there was one "end" too much.
Now, the script appears properly in the menu and the window also opens well.
I managed to integrate the button, to create the message and I created an own function for the code that was remaining underneath.
The isolated code for the run function is as follows:
function LM_LayerTrail:Run(moho)
self.startFrame = moho.document:StartFrame()
self.endFrame = moho.document:EndFrame()
self.moho = moho
local dlog = LM_LayerTrailDialog:new(moho)
dlog:DoModeless()
end
(I kept the definitions of self.startFrame and self.endFrame in that function because the display needs them to update themselves when the window opens.) This works fine. The window opens properly.
I put the remaining code into a new function which is triggered by the button.
The triggering works fine but I think there are things in this function which shouldn't be there.
When pushing the button the lua console shows this error message:
attempt to index global 'moho' (a nil value)
This is the code of my bearish function:
function LM_LayerTrail:ButtonAction(parent)
moho.document:PrepUndo(nil)
moho.document:SetDirty()
local parentLayer = moho.layer
local layer = moho:CreateNewLayer(MOHO.LT_VECTOR)
layer:SetName("Layer Trail")
local mesh = moho:Mesh()
if (mesh == nil) then
return
end
local startFrame = self.startFrame
local endFrame = self.endFrame
local curFrame = moho.frame
local m = LM.Matrix:new_local()
local origM = LM.Matrix:new_local()
local vec = LM.Vector2:new_local()
local origin = parentLayer:Origin()
-- first, create a curve with a new point for each frame of movement
local dashedOn = true
for frame = startFrame, endFrame do
moho:SetCurFrame(frame)
parentLayer:GetFullTransform(frame, m, nil)
vec:Set(origin)
m:Transform(vec)
if (frame == startFrame) then
mesh:AddLonePoint(vec, 0)
else
mesh:AppendPoint(vec, 0)
mesh:SelectNone()
local id = mesh:CountPoints() - 1
mesh:Point(id).fSelected = true
mesh:Point(id - 1).fSelected = true
if (self.dashed) then
if (dashedOn) then
moho:CreateShape(false, layer:CurFrame(), false)
end
else
moho:CreateShape(false, layer:CurFrame(), false)
end
mesh:Point(0).fParent = -1
mesh:Point(mesh:CountPoints() - 1).fParent = -1
dashedOn = not dashedOn
end
end
mesh:SelectNone()
-- next, compensate these points for any movement higher up in the hierarchy
-- examples: the target layer is part of a group with motion of its own, or is attached to a bone
layer:GetFullTransform(0, origM, nil)
for frame = startFrame, endFrame do
layer:GetFullTransform(frame, m, nil)
m:Invert()
for i = 0, mesh:CountPoints() - 1 do
vec:Set(mesh:Point(i).fAnimPos:GetValue(0))
origM:Transform(vec)
m:Transform(vec)
mesh:Point(i).fAnimPos:SetValue(frame, vec)
end
end
moho:SetCurFrame(curFrame)
end
The error message referes to line 3
moho.document:PrepUndo(nil)
Well, I managed to resolve the problem at line 3 by putting code back to the run function. This worked fine until
local curFrame = moho.frame
AS didn't know what to do with it (a nil value). But, I managed it by creating a self object.
But, now I'm stuck at
local origin = parentLayer:Origin()
Do you know why he doesn't find this value and what I could do? Or, am I completely wrong when doing all this?
stefman