getting group name
Moderators: Víctor Paredes, Belgarath, slowtiger
- davoodice2
- Posts: 397
- Joined: Tue Jun 15, 2021 1:14 pm
getting group name
hi
is there function to get parent of layer that is not selected?
for example
moho.layer:Parent("layerName")
is there function to get parent of layer that is not selected?
for example
moho.layer:Parent("layerName")
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
- synthsin75
- Posts: 10267
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: getting group name
As long as you're storing the unselected layer object (moho.layer) to a variable, even with it unselected, you can do:
var:Parent()
and
var:Parent():Name()
var:Parent()
and
var:Parent():Name()
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
- davoodice2
- Posts: 397
- Joined: Tue Jun 15, 2021 1:14 pm
Re: getting group name
thanks. and how can I select a layer ? SetSelLayer()? what is it's argument? is there any better way?synthsin75 wrote: ↑Tue Aug 31, 2021 4:57 pm As long as you're storing the unselected layer object (moho.layer) to a variable, even with it unselected, you can do:
var:Parent()
and
var:Parent():Name()
I want store current selected layer to select it later.
how to get current selected layer ID?
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
- hayasidist
- Posts: 3841
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: getting group name
if you've got the current active layer and decided that the right thing is to select a different one, make sure that you have a variable that addresses a MohoLayer object (e.g. var = moho.layer:Parent() to get the active layer's parent) then
moho:SetSelLayer(var) will selected the layer identified by "var" in the layers window
ScriptInterface:SetSelLayer(layer, multiSelect, allowDeselect) : see https://mohoscripting.com/methods/60
As Wes has said, you don't need the layer to be selected to work on it ... so (e.g.) you can find the parent, then do something with some / all the child layers but still leave the one original child layer selected
moho:SetSelLayer(var) will selected the layer identified by "var" in the layers window
ScriptInterface:SetSelLayer(layer, multiSelect, allowDeselect) : see https://mohoscripting.com/methods/60
As Wes has said, you don't need the layer to be selected to work on it ... so (e.g.) you can find the parent, then do something with some / all the child layers but still leave the one original child layer selected
- davoodice2
- Posts: 397
- Joined: Tue Jun 15, 2021 1:14 pm
Re: getting group name
thanks. but can you give me an example of 2 line code for store current layer and select that later? I dont understand var in lua. Take it easy on mehayasidist wrote: ↑Tue Aug 31, 2021 6:30 pm if you've got the current active layer and decided that the right thing is to select a different one, make sure that you have a variable that addresses a MohoLayer object (e.g. var = moho.layer:Parent() to get the active layer's parent) then
moho:SetSelLayer(var) will selected the layer identified by "var" in the layers window
ScriptInterface:SetSelLayer(layer, multiSelect, allowDeselect) : see https://mohoscripting.com/methods/60
As Wes has said, you don't need the layer to be selected to work on it ... so (e.g.) you can find the parent, then do something with some / all the child layers but still leave the one original child layer selected
Code: Select all
function DV_select_Bone_Layer:Run(moho,group)
local isFound = false
local prev_name = moho.layer:Name()
local parent = moho.layer:Parent()
if (parent == nil) then
LM.Beep()
moho:SetSelLayer(prev_name)
return -1
end
moho:SetSelLayer(parent)
local layet_type = moho.layer:LayerType(parent)
if(layet_type==MOHO.LT_BONE) then
isFound=true
return -1
end
while not isFound do
moho:SetSelLayer(parent)
parent = moho.layer:Parent()
if parent == nil then
LM.Beep()
print(prev_name)
moho:SetSelLayer(prev_name)
break
end
layet_type = moho.layer:LayerType(parent)
if(layet_type==MOHO.LT_BONE) then
isFound=true
end
end
end
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
- synthsin75
- Posts: 10267
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: getting group name
SetSelLayer doesn't accept names, as more than one layer could have the same name. It needs the layer object.
local layer_object = moho.layer
moho:SetSelLayer(layer_object)
local layer_object = moho.layer
moho:SetSelLayer(layer_object)
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
- hayasidist
- Posts: 3841
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: getting group name
var is just an arbitrary variable namedavoodice2 wrote: ↑Tue Aug 31, 2021 7:10 pm thanks. but can you give me an example of 2 line code for store current layer and select that later? I dont understand var in lua. Take it easy on me
replace the name "layer_object" that Wes used with "var"...
local var = moho.layer
moho:SetSelLayer(var)
If you're struggling with Lua: Moho currently uses 5.2: http://www.lua.org/manual/5.2/
- davoodice2
- Posts: 397
- Joined: Tue Jun 15, 2021 1:14 pm
Re: getting group name
Perfect!
thank you two friends.
thank you two friends.
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
- davoodice2
- Posts: 397
- Joined: Tue Jun 15, 2021 1:14 pm
Re: getting group name
Can i select parent layer of a layer that isn't selected ?davoodice2 wrote: ↑Tue Aug 31, 2021 6:04 pmthanks. and how can I select a layer ? SetSelLayer()? what is it's argument? is there any better way?synthsin75 wrote: ↑Tue Aug 31, 2021 4:57 pm As long as you're storing the unselected layer object (moho.layer) to a variable, even with it unselected, you can do:
var:Parent()
and
var:Parent():Name()
I want store current selected layer to select it later.
how to get current selected layer ID?
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
- hayasidist
- Posts: 3841
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: getting group name
yes - as long as you have (or can get) the MohoLayer object for the layer whose parent you want -- it doesn't have to be the selected layer -- e.g.
you have a selected layer: (moho.layer)
you find its parent: parent = moho.layer:Parent() (which is not the selected layer!)
and now you want the "grandparent": gp = parent:Parent()
if you then want to make that the selected layer: moho:SetSelLayer(gp)
or if you just want to see all the gp's children..
gp = moho:LayerAsGroup(gp)
for i = 0, gp:CountLayers()-1 do
.. child = gp:Layer(i)
you have a selected layer: (moho.layer)
you find its parent: parent = moho.layer:Parent() (which is not the selected layer!)
and now you want the "grandparent": gp = parent:Parent()
if you then want to make that the selected layer: moho:SetSelLayer(gp)
or if you just want to see all the gp's children..
gp = moho:LayerAsGroup(gp)
for i = 0, gp:CountLayers()-1 do
.. child = gp:Layer(i)
- davoodice2
- Posts: 397
- Joined: Tue Jun 15, 2021 1:14 pm
Re: getting group name
its related to current selected object. I want to select parent of a layer that isn't select now. for eg:hayasidist wrote: ↑Thu Sep 02, 2021 1:18 pm yes - as long as you have (or can get) the MohoLayer object for the layer whose parent you want -- it doesn't have to be the selected layer -- e.g.
you have a selected layer: (moho.layer)
you find its parent: parent = moho.layer:Parent() (which is not the selected layer!)
and now you want the "grandparent": gp = parent:Parent()
if you then want to make that the selected layer: moho:SetSelLayer(gp)
or if you just want to see all the gp's children..
gp = moho:LayerAsGroup(gp)
for i = 0, gp:CountLayers()-1 do
.. child = gp:Layer(i)
i selected foot layer. but I want to select parent of head layer.
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
- synthsin75
- Posts: 10267
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: getting group name
Store the head layer object to a variable and you can select its parent layer any time you like.davoodice2 wrote: ↑Thu Sep 02, 2021 2:22 pm its related to current selected object. I want to select parent of a layer that isn't select now. for eg:
i selected foot layer. but I want to select parent of head layer.
And if you haven't stored the layer object, as long as you have some way to identify the layer, like unique name, tag, UUID, etc., you can always iterate through all the layers in the document until you find it: https://mohoscripting.com/snippets/1
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
- davoodice2
- Posts: 397
- Joined: Tue Jun 15, 2021 1:14 pm
Re: getting group name
if want to tell more clearly. I select a layer and i want to find all parents of this layer and do some thing on them. use for loop or some thing like that.synthsin75 wrote: ↑Thu Sep 02, 2021 5:20 pmStore the head layer object to a variable and you can select its parent layer any time you like.davoodice2 wrote: ↑Thu Sep 02, 2021 2:22 pm its related to current selected object. I want to select parent of a layer that isn't select now. for eg:
i selected foot layer. but I want to select parent of head layer.
And if you haven't stored the layer object, as long as you have some way to identify the layer, like unique name, tag, UUID, etc., you can always iterate through all the layers in the document until you find it: https://mohoscripting.com/snippets/1
I think it isn't good if i write:
moho.layer:Parent():Parent():Parent():.....
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
- hayasidist
- Posts: 3841
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: getting group name
that will work unless you hit the end of the "family tree" -- see my previous post about getting a grandparent -- add to that a test to see if there's a parent.. e.g if not gp then ...davoodice2 wrote: ↑Fri Sep 03, 2021 5:51 am I think it isn't good if i write:
moho.layer:Parent():Parent():Parent():.....
Code: Select all
parent = moho.layer:Parent()
if parent then
gp = parent:Parent()
if gp then ...
Code: Select all
function getParent (layer)
local parent = layer:Parent()
if parent then
getParent (parent)
...
...
end
- davoodice2
- Posts: 397
- Joined: Tue Jun 15, 2021 1:14 pm
Re: getting group name
Oh God how dumb I am.hayasidist wrote: ↑Fri Sep 03, 2021 9:11 amthat will work unless you hit the end of the "family tree" -- see my previous post about getting a grandparent -- add to that a test to see if there's a parent.. e.g if not gp then ...davoodice2 wrote: ↑Fri Sep 03, 2021 5:51 am I think it isn't good if i write:
moho.layer:Parent():Parent():Parent():.....or you can get cute and use recursion to seek out the root:Code: Select all
parent = moho.layer:Parent() if parent then gp = parent:Parent() if gp then ...
Code: Select all
function getParent (layer) local parent = layer:Parent() if parent then getParent (parent) ... ... end
I had think I can get parent just with moho.layer:Parent()
now i find out layer:Parent() because of inheritance
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش