[Closed] Layermanager problem
ok got a simple problem I think I’m just not seeing whats blatently in front of my eyes basically what I need is to turn layer child nodes into an array but in the fashion that if the mesh/point whatever is in layer 1 then it will be 1 and if there are 5 items in layer 1 then there will be 5 1’s and so on and so fourth…
So I have the whole script written out where I now find all the layer children “Skipping layer 0 of course”
for i = 0 to layerManager.count-2 do(
B=i+1
layer = ILayerManager.getLayerObject B
layerNodes = refs.dependents layer
print layerNodes
)
so theoretically a scene where there are 5 meshes in layer 1 and 2 points in layer 2 I should get an array like this
1,1,1,1,1,2,2
layerNodes in the code is correct I just don’t know how to convert that into a numerical array where it can be manipulated in the fashion I need.
Seems I have found the answer.
Here’s the code if anyone else is interested in doing anything similar.
Layer_array=#()
for i = (LayerManager.count-1)to 1 by -1 do(nodeparent=(LayerManager.getlayer i).name (LayerManager.getLayerFromName nodeparent).nodes &nodes)
if you want just select there is an easier way:
(layermanager.getlayerfromname name).select on
I have a new problem I have to separate the geometry and the helpers in “nodes” in layers but nothing seems to be working.
Here is my current code
clearlistener()
Layer_array=#()
(LayerManager.getLayer 0).current = true
for i = (LayerManager.count-1)to 1 by -1 do append Layer_array(LayerManager.getlayer i).name
for i = 1 to Layer_array.count do((LayerManager.getLayerFromName Layer_array[i]).nodes &nodes
if nodes == geometry then(
print nodes
)
else(
)
)
this is supposed to print any geometry in layers that aren’t in the first layer. Can anyone spot where I went wrong? When I print nodes outside the IF statement it shows the array has Editable_mesh
Try this one
fn collectLayerNodes = if (cnt = LayerManager.count-1) > -1 do
(
local getLayByName = LayerManager.getLayerFromName
local getLay = LayerManager.getLayer
(getLayByName "0").current = on
for i = 0 to cnt where not (layer = (getLay i).layerAsRefTarg).current collect
(
if (nodes = refs.dependentNodes layer).count == 0 then dontcollect else
(
data = #()
for n in nodes do
(
case (superclassof n) of
(
(geometryclass): append data 1
(helper): append data 2
)
)
#(layer.name,(sort data))
)
)
)
/*
layersData = collectLayerNodes()
print layersData
*/
I used “case of” statement in case you want to expand fn by adding more classes (ei.superclasses). Also this fn will exclude all empty layers
In this update fn will exclude also layers which contains not specified classes.
Question : are you plan to consider more then geometry and helper calsses?
fn collectLayerNodes = if (cnt = LayerManager.count-1) > -1 do
(
local getLayByName = LayerManager.getLayerFromName
local getLay = LayerManager.getLayer
(getLayByName "0").current = on
for i = 0 to cnt where not (layer = (getLay i).layerAsRefTarg).current collect
(
if (nodes = refs.dependentNodes layer).count == 0 then dontcollect else
(
data = #()
state = on
for n in nodes do
(
case (superclassof n) of
(
(geometryclass): append data 1
(helper): append data 2
default: state = off
)
)
if state then #(layer.name,(sort data)) else dontcollect
)
)
)
Thanks I was able to edit the code for my needs and it works flawlessly.
data = #()
data1 = #()
clearlistener()
Layer_array=#()
for i = (LayerManager.count-1)to 1 by -1 do(
nodeparent=(LayerManager.getlayer i).name
(LayerManager.getLayerFromName nodeparent).nodes &nodes
for n in nodes do(
case (superclassof n) of(
(geometryclass): append data nodes.count
(helper): append data1 nodes.count
)
)
)
But you are requested this output???
so theoretically a scene where there are 5 meshes in layer 1 and 2 points in layer 2 I should get an array like this
Code:
[left]1,1,1,1,1,2,2[/left]
You know what, I appologize I guess thats a bonehead moment but I meant to get them in separate arrays but in any case your method works good sorry for the confusion
in different places from different people i saw:
nodes = refs.dependentNodes layer
as method to get layer nodes. this is not right!
layer has a method nodes(), and only this method 100% correct.
Shorter version
fn collectLayerNodes superClasses: = if (cnt = LayerManager.count-1) > -1 do
(
local getLayByName = LayerManager.getLayerFromName
local getLay = LayerManager.getLayer
(getLayByName "0").current = on
for i = 0 to cnt where not (layer = (getLay i).layerAsRefTarg).current collect
(
if (nodes = refs.dependentNodes layer).count == 0 then dontcollect else
(
array = for n in nodes where (e = findItem superClasses (superclassof n)) > 0 collect e
if array.count > 0 then #(layer.name,(sort array)) else dontcollect
)
)
)
collectLayerNodes superClasses:#(geometryClass, helper)
Even if I use “layerAsRefTarg”. I’ve never had a problem with this.
Can you tell what can cause issue by using my method?