Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get all nodes under a layer with pymxs

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
2447 Views, 4 Replies

Get all nodes under a layer with pymxs

Hi,

I try to get all nodes from a layer with the pymxs module to e.g. delete the nodes and the layer with pymxs.

 

maxscript example:

 

layer = LayerManager.getLayerFromName "test_layer";
layer.nodes &theNodes;

# Result:
#($Teapot:Teapot001 @ [29.285393,-25.283651,0.000000])

 

 

At first I tried to translate the maxscript code into a pymxs version but the node property seems not to work in pymxs.

 

from pymxs import runtime as rt
layer = rt.LayerManager.getLayerFromName("test_layer")

# These are the results that I get when I tried to access the node property in pymxs
layer.nodes #result: nodes()
layer.nodes() #result: -- Argument count error: nodes wanted 1, got 0
layer.nodes(0) #result: True
layer.nodes("Teapot001") #result: True
...

 

 

I found some other solutions to get the nodes from a layer (see below). But these solutions are much more complex than the maxscript example. So I just want to know why the nodes property is not working as expected in pymxs?

 

working pymxs example:

 

from pymxs import runtime as rt
layer = rt.LayerManager.getLayerFromName("test_layer")
nodes = rt.refs.dependents(layer.layerAsRefTarg)

# Result:
#($Teapot:Teapot001 @ [29.285393,-25.283651,0.000000], ReferenceTarget:NodeRefMgr, ReferenceTarget:LayerManager, $<rootScene>)

# Or
rt.clearSelection()
layer.select(True)
nodes = rt.getCurrentSelection()
# Result:
#($Teapot:Teapot001 @ [29.285393,-25.283651,0.000000])

 

 

4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

This is the solution to use the nodes property from the layers mixin interface. But this one works only in 3ds Max 2021. Thanks to Jason (the master of pymxs) .

import pymxs
rt = pymxs.runtime

layer = rt.LayerManager.getLayerFromName("test_layer")
res, nodes = layer.nodes(pymxs.byref(None))

 

Message 3 of 5
suzipolklittle
in reply to: Anonymous

Anyone know how I could add an object to a layer with pymxs?

note: I have the object's name, and it's not selected. So I would need to add the item to the layer by giving the command the name of the item.

 

(I haven't been able to figure out how to select an item with pymxs, only all items in the scene.. so I've done a workaround to select all items and then loop through, checking for the item I need)

 

Message 4 of 5

Oh hey, I figured out how to select my object -- so now I guess I just need to figure out how to add that selected object to my layer. 

 

I've successfully been able to make my layer with 

rt.LayerManager.newLayerFromName("export")

 

(this makes a layer named "export") 

Now I just am trying to figure out how to put my object into that layer (that I can now select, yoo hoo!)

 

Any help with this would be greatly appreciated! I'm very new to pymxs and maxScript also..

(only really know Python and MEL currently)

 

Thanks you!

Tags (1)
Message 5 of 5

Oh hey -- I got a solution. (from another site..)

# creates a layer named "export" and adds our asset to it
obj = rt.getNodeByName("your_object_name")
layer = rt.LayerManager.newLayerFromName("export")
layer.addnode(obj)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report