Notifications
Clear all

[Closed] Layermanager problem

what is layerAsRefTarg? it’s a max objects. you can use max object almost anywhere (CA, script controllers, trackview nodes, etc.) so technically it’s not hard to make a dependency whit this object;

do i want to see a problem? here is it:

layerCA = attributes layerCA (parameters params (layerRT type:#maxobject;))
 l = LayerManager.newLayer()
 b = box()
 custattributes.add b layerCA baseobject:off
 b.layerCA.layerRT = l.layerAsRefTarg
 refs.dependentnodes l.layerAsRefTarg
3 Replies
(@gazybara)
Joined: 11 months ago

Posts: 0

The last line returns only Box object which is good.

(@denist)
Joined: 11 months ago

Posts: 0

why is it good? box is not in this layer

(@gazybara)
Joined: 11 months ago

Posts: 0

oops! I did’nt check layer manager.
Yup. You are right

refs.dependentnodes is recursive function… that’s might cause another problem… some nodes from layer list can have dependency with other nodes not from the same layer.

That’s it!
Denis, You need to write the book “MXS Hidden Gems” immediately!
It’s about time. I hope that all members agree with me.
BTW this is the last update.

fn collectLayerNodes superClasses: = if (cnt = LayerManager.count-1) > -1 do
 (
 	local getLayByName = LayerManager.getLayerFromName
 	local getLay = LayerManager.getLayer
 	for i = 0 to cnt where (layer = getLay i).name != "0" collect
 	(
 		if (layer.nodes &nodes ; nodes).count == 0 then dontcollect else 
 		(
 			array = for node in nodes where (e = findItem superClasses (superclassof node)) > 0 collect e
 			if array.count > 0 then #(layer.name,(sort array)) else dontcollect
 		)
 	)
 )
 layerData = collectLayerNodes superClasses:#(geometryClass, helper)
 print layerData
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

colored in red should be fixed. so it’s probably not final.

You need to explain what is wrong now?
Code works fine:hmm:

2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

well, well, well… a code is good when it not just works but also looks nice
let’s start from the middle:

for i = 0 to cnt where (layer = getLay i).name != "0" collect

there is no way to make duplicated by name layers… the first layer is always the default layer with the name “0”

so you can just start from index 1 and not do any name check. does it make sense?
do you want me to explain the first highlighting?

(@gazybara)
Joined: 11 months ago

Posts: 0

I did’nt know that. I often add prefix to the layer name “#” (“#NewLayer“) which will be placed above layer “0” in layer manager list. That’s why I thought that alphabetical order is important here like in .net ListView control. Ok.

for i = 1 to cnt collect ()

This is fixed, what’s next?

Wow you guys are giving me so many ideas on things I didn’t even know were possible. This is by far the most helpful website on the net for maxscript due to the sheer advantage in knowledge this community has. :bowdown: :bowdown: :bowdown:

true. this is the best resource

the first highlight…
you check there if number of layers more than zero. see may comment above. every max scene must have default layer, so the number of layers is always more than 0

 fn collectLayerNodes = if (cnt = LayerManager.count-1) > 0 do
  (
 	 local getLayByName = LayerManager.getLayerFromName
 	 local getLay = LayerManager.getLayer, layer
 	 for i = 1 to cnt where ((layer = getLay i).nodes &nodes ; nodes).count > 0 collect
 	 (
 		array = for n in nodes collect
 		(
 			case (superclassof n) of
 			(
 				(geometryclass): 1
 				(helper): 2
 				default: dontcollect
 			)
 		)
 		if array.count > 0 then #(layer.name,(sort array)) else dontcollect
 	 )
  )
  layerData = collectLayerNodes()
Page 2 / 2