Share

Accessing MAXScript PathName Values

The $ notation in MAXScript indicates a PathName literal value, for example $Box001 is the node with the name "Box001".

You can create PathName values in Python by executing a standard MAXScript path string. So for example, running mypath = safeexecute "$Box*" will return a PathName object to all the objects named "Box*" in the scene.

Note:

Prior to 3ds Max 2023, safeexecute() did not exist, you will need to use execute().

This is a more elaborate example that shows some of the things you can do with the PathValue:

from pymxs import runtime as rt
import pymxs

def create_path(s):
    return rt.safeExecute(s)

# reset max fileox
rt.resetmaxfile(rt.name("noPrompt"))
# create 10 boxes and 10 spheres:
for i in range(int(1), 1 + int(10)):
    rt.box(pos=rt.point3(i * 50, 0, 0))
for i in range(int(1), 1 + int(10)):
    rt.sphere(pos=rt.point3(i * 50, 100, 0))


# these path objects can be iterated!
for thing in create_path("$Box*"):
    print(thing)


# assign standard material to all boxes
create_path("$Box*").material = rt.standard()
# argh! does not work in python!
print(create_path("$Box001").material)

# do the same in maxscript
rt.execute("$Box*.material = standard()")
# works perfectly well!
print(create_path("$Box001").material)

In addition to using ecute()/execute(), you can evaluate a StringStream that contains a MAXScript PathName Literal with readValue() and use the result in any function that takes a node or node list, for example if you want to use select():

rt.select(rt.readvalue(rt.StringStream('$Box001')))

In this instance you could also use rt.getNodeByName(), but that method takes a name rather than a scene path, and does not support wildcards.

Was this information helpful?