Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

MXS: Layermanager

MXS: Layermanager

istan
Advisor Advisor
1,724 Views
5 Replies
Message 1 of 6

MXS: Layermanager

istan
Advisor
Advisor

Can anyone explain to me, how to select all nodes from layer?

The example in the help does not enlighten me.. What is "refs.dependents" ?

https://help.autodesk.com/view/MAXDEV/2021/ENU/?guid=GUID-79537E16-FE25-4567-BEA6-06F39E0A5C1F 

 

 

for i = 0 to layerManager.count-1 do
(
  ilayer = layerManager.getLayer i
  layerName = ilayer.name
  layer = ILayerManager.getLayerObject i
  layerNodes = refs.dependents layer
  format "Layer: %; nodes: %\n" layerName layerNodes
)

 

 

 

0 Likes
Accepted solutions (1)
1,725 Views
5 Replies
Replies (5)
Message 2 of 6

istan
Advisor
Advisor
Accepted solution

answered by myself..

layer.select true
delete $

was it..

0 Likes
Message 3 of 6

miauuuu
Collaborator
Collaborator

Why this not works?

(
	layer = layermanager.getLayerFromName "Layer002"
	thisLayerObjsArr = #()
	layer.nodes &thisLayerObjsArr
	
	delete thisLayerObjsArr
-- 	select thisLayerObjsArr
)
https://miauu-maxscript.com/
0 Likes
Message 4 of 6

istan
Advisor
Advisor

ok.

But it still did not answer, what the code from the doc shall do:

layerNodes = refs.dependents layer

 

0 Likes
Message 5 of 6

denisT.MaxDoctor
Advisor
Advisor

as you know the latest versions of MAX allow nested layers. So the above methods are actually not entirely correct. There are no built-in methods to get ALL the nodes of a layer, including from nested layers. So, we have to recurse to get them all ... something like:

fn getLayerNodes layer list: recurse:on = 
(
	layer.nodes &nn
	join list nn
	if recurse do for k=1 to layer.getNumChildren() do 
	(
		getLayerNodes (layer.getChild k) list:list recurse:on
	)

	list
)

a = layermanager.getLayer <k> 
nn = getLayerNodes a list:#()

 

 


@istan wrote:

ok.

But it still did not answer, what the code from the doc shall do:

layerNodes = refs.dependents layer

 


This does not work if the "layer" value is interface. You must use its reference target (BaseLayer object) to get dependents. These dependent items include immediate nodes (not nested) and some other dependent reference targets that can be different.

 

refs.dependentnodes might give you right list of immediate nodes, not it's not exactly correct in general

 

0 Likes
Message 6 of 6

istan
Advisor
Advisor

Hi Denis,

layer hierarchy was clear - and the rest now as well. Thx.

How about the other task we were talking about ? When "we" will find time ? 😉

Istan

0 Likes