Page 1 of 1
Embedded Script Working Inside Layer Groups (Question)
Posted: Wed Aug 24, 2005 9:20 am
by Rai López
Well, I'm involved in a very first steps of Embedded Scripting, ejem, ejem... you know... I'm very sorry

, but I'm fill of basic and (possibly) stupid questions... Well, seems that the "target_object.lua", embedded script sample made by the GREAT Marble, only take effect about direct layers of Moho, nothing about layers inside a group... because when you make a group and drag all layers of "targeting_sample.moho" inside that group, you receibe the message: "Target layer not found" because Target layers is not detected... I was wondered about the way to avoid this, I've been
investigating without results and I'd like to know the code lines (or some clue at least) for it can works with layers inside a certain group... I think that I must change, add or eliminate something at this lines of code...
Code: Select all
local targetLayer = moho.document:LayerByName("Target")
if (targetLayer == nil) then
print("Target layer not found.")
return
end
...but I don't know what, and I'm afraid I need some help or clue... If somebody could help me on this search, I'd be very GRATEFULL! *CIAO*
Posted: Wed Aug 24, 2005 10:37 am
by Lost Marble
The document:LayerByName function only looks at top-level layers. There is also a group:LayerByName function that returns a layer in a group.
To dig way down for a layer that is inside multiple groups, you may have to use this function several times:
Code: Select all
local layer= moho.document:LayerByName("Group1")
if (layer == nil) then
print("Group1 not found.")
return
end
layer = moho:LayerAsGroup(layer)
layer = layer:LayerByName("Sub-Group2")
if (layer == nil) then
print("Sub-Group2 not found.")
return
end
layer = moho:LayerAsGroup(layer)
layer = layer:LayerByName("The Layer I Want")
if (layer == nil) then
print("The Layer I Want not found.")
return
end
Posted: Wed Aug 24, 2005 10:51 am
by Rai López
...WOW!!!
THANK YOU! THANK YOU!! THANK YOU!!!

Thank you very much LM for the quick answer!

I really needed help with this and now I can't wait to try it! You've created an
INCREDIBLE feature and I can't be more GRATEFULL
*CIAO*
PS:
EMBEDDED SCRIPTS (can)
ROCKS!!! 
Posted: Sun Oct 02, 2005 2:04 pm
by Rai López
...HELLO! The "group:LayerByName function" works

, yes... but I'm wondering if really is the one way to get that one layer locates another layer
(...or bone?) inside the same group because when you move all that group inside/outside a new group you obtain an error and you must rewrite (add or remove part of the code) the script for it works again... I mean, if two layers like in the case of Targering example are inside the SAME group, is not possible that the script only search for the other layer INSIDE this group? Independently of the level where the group be situated? Seems logic and I have the curiosity/necessity of be sure to can work in my Bone_Control embedded script (to can control one bone with the movement of other situated in other Bone Layer, but both inside the same group) Uf... I hope someone can HELP me in this
impossible task

BYE! (and THANKS)
Posted: Sun Oct 02, 2005 6:04 pm
by 7feet
Maybe something like this:
Code: Select all
local layer = moho.layer --layer you're on
local parent = LayerAsGroup(layer:Parent()) -- the parent layer if it has one
local target = nil --where the target goes if you find one
if (parent == nil) then --No parent, so it's a root layer
target = moho.document:LayerByName("Target")
if (target == nil) then
print("Target not found.")
return
end
else
-- It's inside some "group" type of layer
target = parent:LayerByName("Target")
if (target == nil) then
print("Target not found.")
return
end
end
Something like that should do it, I think. I haven't tried it, so I may have done something dumb, but it looks about right. Give it a shot.
Also, LM, I don't know if it was added later, but LayerByName isn't in the Scripting Reference. I think there's a few other bits, has the Ref been updated lately? Thanks
Posted: Sun Oct 02, 2005 6:20 pm
by Rai López
THANK YOU 7feet!!! ...I'm now a little desperate

about all this "Bone_Control" embedded script that I'm treating to do... so I think I'm going to the bed now, forget it for an hours and try it tomorrow, hopping that things going better... (maybe your codes help

) so
THANKS! (and good night

).
Posted: Mon Oct 03, 2005 2:43 pm
by Rai López
HELLO 7feet, LM and others...

I've "insert" the code that you bring us and apply the script to the targeting_sample.moho file but, of course, with the "Target" and "Scripted Group" layers inside a group... well I obtain this error in the Lua Console:
...\Target_ObjectInAnyGroup.lua:11:attempt to call global 'LayerAsGroup" (a nil value)
I dont' know if I'll have done something wrong (as usually), or what the cause of the error is, because I can't understand what does it means (as usually too

) ...I only can put this here for if this can help someone to solve the problem or know about it... CIAO!

Posted: Mon Oct 03, 2005 3:56 pm
by 7feet
Oops. Try this bit (I forgot something - picky damn computers)
local parent = moho:LayerAsGroup(layer:Parent())
alternately, just "local parent = layer:Parent()" might work fine too, you'd have to test it.
Posted: Mon Oct 03, 2005 4:05 pm
by mr. blaaa
yeeehaaw!

Posted: Mon Oct 03, 2005 4:29 pm
by Rai López
7feet, YOU ARE HERE! And you come with some homeworks to me

, VIVA! Jaja... and some of they, like a good pupil, I had made it before

...because I think I tryed the
local parent = moho:LayerAsGroup(layer:Parent()) sugestion yet and other error appeared, I'll treat to repeat it to be sure and, if necessary put here the Lua Console information. About the other thing... I'm going to try it now!

And I'll put here the results! THANKS!!!
PS: Mmm... Jaja, I don't know how to ask... ammm... can you tell me something about the Bone_Control script issue? Anything? It's only for curiosity... PLEASE, I don't want that you think I want to put pressure on you

but you puted some of HOPE over all this and now I can't think in other thing!

Jaja...
SORRY 
and
THANK YOU for all! CIAO!!!

Posted: Tue Oct 04, 2005 3:37 pm
by Rai López
Hmmm... seems that don't work to me yet... I have tried all the possibilities and 7feet suggestions but nothing

...I suppose that there is something that I'm doing wrong, but the script even
crash Moho if I apply directly in a parent (not sub-layer) layer instead display an error in Lua Console... Well, I'll go on investigating... BYE!
