[3dsmax] maxscript > Python >> list Objects in Layer?

Hello,

I am using Blur3d.API.

I am having an hard time to find out how to list objects from layer using python…

From the documentation :

layer.nodes &theNodes
--> true
 
theNodes
--> #($Sphere:Sphere10 @ [0.000000,0.000000,0.000000], $Sphere:Sphere09 @ [0.000000,0.000000,0.000000],.... 

But well, not sure to understand the & before theNodes.

How could it be translated to python?

I tried things like :

len(layer.nodes)

But always giving 0 actually.

Any idea on how to list objects from layers with Pythons?

Thanks for your help :p:

&theNodes syntax confused me at first, too.

in max script (and likely in python) &theNodes indicates a by reference array called theNodes

The by reference part means that it’s not an array of objects or values, but an array of references to the objects/values.
thus, if some external operation alters an element that the array references, the array will “know” that that element has changed.
in pratice, you can operate on theNodes like any ordinary array.

So , the command layer.nodes &theNodes basically says:
"run the method layer.Nodes
and put references to resulting items into an array called theNodes

len(layer.nodes) returns 0 because its a method, not an array -I think so, anyhow.
Try using type() to see what python thinks they are.


layer.nodes &theNodes
type (layer.nodes)
type (theNodes)

hmm then if the & method should be python, I have no idea why it does commit an error…

Look, below the code I am using :

from Py3dsMax import mxs

layer = mxs.LayerManager.getLayerFromName ('Layer_Test')

layer.nodes &theNodes
print type (layer.nodes)
print type (theNodes)

 

but mainly getting an error on layer.nodes &theNodes.

  File "<string>", line 5, in <module>
TypeError: unsupported operand type(s) for &: 'value_wrapper' and 'list'

Then trying to set the theNodes theNodes = [], but same error…

Any idea? :sick:

EDIT :

print type(layer.nodes)

will give

>>> <type 'value_wrapper'>

Assuming layer.nodes is a method, what you’d want to do is to call the method using parentheses and assign the result to a variable.

theNodes = layer.nodes()

In python “&” is the bitwise AND operator.

Yes, python value identifiers must be case sensitive alpha-numeric with undescores only.

Hi,

as the variable in python will not get the result, you need to do a little bit of MaxScript in Python.

This is a way that works:


from Py3dsMax import mxs

# Get Layer
myLayer = mxs.LayerManager.getLayerFromName("Test")

# Create a max-function to wrap the operation (this will be a new global function)
mxs.execute("function getLayerNodes layerInterface = ( layerInterface.nodes &outputList; outputList)")

# Call this new (global) max-function and receive the nodes
getNodes = mxs.getLayerNodes(myLayer)

# Here they are :-)
print (getNodes)

Of course, it’s not the “most pythonic” solution but the only one that works definitely.

Have fun!
Chris

@chris >> This one works perfectly thanks!
Sorry for the delayed answer… I was between Maya and Unity =__=.

Alright, I should be back on 3dsmax for the whole week.