ScriptSpot is a diverse online community of artists and developers who come together to find and share scripts that empower their creativity with 3ds Max. Our users come from all parts of the world and work in everything from visual effects to gaming, architecture, students or hobbyists.
Looking for a script to rename all objects on a layer to the name of that layer.
This should work for multiple selected layers. Unselected layers should be ignored.
Yup. By removing "uniquename" function in this line for n in nodes do n.name = uniquename layer.name
This line need to look like this for n in nodes do n.name = layer.name
Could someone please add description to the end of each line to describe how this works. In particular how does the script know to go down each layer one by one.
fn renameLayerNodes considerZeroLayer:on =
(
e = if considerZeroLayer then 0 else 1
local getLay = LayerManager.getLayer, layer
for i = e to layerManager.count-1 where ((layer = getLay i).nodes &nodes ; nodes).count > 0 do
(
for n in nodes do n.name = uniquename layer.name
)
)
renameLayerNodes()
You need to learn the way how maxscript works ei. execute code.
Max Script Help document will help you a lot to understand this.
Anyway...
-- define function "renameLayerNodes" with one argument-- argument "considerZeroLayer" represent the state that can be "ON" or "OFF" ei. "true" or "false"
fn renameLayerNodes considerZeroLayer:on =
(-- depending on "considerZeroLayer" variable "e" will hold integer 0 (if "true") or 1 (if "false")-- first layer in LayerManager is always "0" and GUI treelist control (.NET) contains items (layers)-- where first index is zero-based.
e = if considerZeroLayer then 0 else1-- declare local variable "getLay" that will hold LayerManager Interface function-- and variable "layer" that will hold actual layer
local getLay = LayerManager.getLayer, layer
-- this "for-loop" iterates through a range of numbers from e which is 0 or 1 to number of layers (count) in LayerManager-- taking into account only layers that are not emptyfor i = e to layerManager.count-1 where ((layer = getLay i).nodes &nodes ; nodes).count > 0 do(-- "&nodes" is an array of all nodes (objects) on the layer in the by-reference Out parameter-- loop trough all object in the "nodes" array and rename each object with unique name (base name is the object layer name)for n in nodes do n.name = uniquename layer.name
))-- execute above defined function-- you can use two forms to execute function where argument have state "ON"
renameLayerNodes()-- or
renameLayerNodes considerZeroLayer:on
-- but if you decide to change argument state to "OFF" use only this form
renameLayerNodes considerZeroLayer:off
Try this fn.
If "considerZeroLayer" argument is off then "0" layer will be skiped (default on)
fn renameLayerNodes considerZeroLayer:on =
(
e = if considerZeroLayer then 0 else 1
local getLay = LayerManager.getLayer, layer
for i = e to layerManager.count-1 where ((layer = getLay i).nodes &nodes ; nodes).count > 0 do(for n in nodes do n.name = uniquename layer.name
))
renameLayerNodes()
Yeah its a strange request, Right now I have 154 layers with 100s of objects on some layers. all requiring the same name. would take forever naming a layer than naming all the objects on that layer.
Thats sound strange to me... For example, the default layer has preserved name "0", and if you have 20 objects inside that layer, you wan to rename all of them to "0"? I never will do that, but never mind...
How to work with layers is very well explained in the mxs docs, however, I not see any way to catch which layer is selected. You can use layer.ON property instead of selection. If that applicable, try this very lightly modification of the code example in the help file:
for i = 0 to layerManager.count-1 do(
ilayer = layerManager.getLayer i
layerName = ilayer.name
if ilayer.on do(
layer = ILayerManager.getLayerObject i
layerNodes = refs.dependents layer
layerNodes.name = layerName
))
Comments
Anubis,
is it possible to rename objects by layer name without adding number at the name end?
I seem can't find a way to remove redundant part of the code.
...
Yup. By removing "uniquename" function in this line
for n in nodes do n.name = uniquename layer.nameThis line need to look like this
for n in nodes do n.name = layer.namebga
layer by layer
Could someone please add description to the end of each line to describe how this works. In particular how does the script know to go down each layer one by one.
fn renameLayerNodes considerZeroLayer:on =
(
e = if considerZeroLayer then 0 else 1
local getLay = LayerManager.getLayer, layer
for i = e to layerManager.count-1 where ((layer = getLay i).nodes &nodes ; nodes).count > 0 do
(
for n in nodes do n.name = uniquename layer.name
)
)
renameLayerNodes()
...
You need to learn the way how maxscript works ei. execute code.
Max Script Help document will help you a lot to understand this.
Anyway...
bga
re-name all objects to each objects layer name
Has anyone worked out how to re-name all object to each objects layer name?
This will help when all objects imported into the scene have the same name.
...
Try this fn.
If "considerZeroLayer" argument is off then "0" layer will be skiped (default on)
bga
Bang on, that's cool. How
Bang on, that's cool. How does it add increments on the end of multiple objects in the same layer? Thanks a bunch really saved some time here.
...
By using this
bga
Yeah its a strange request,
Yeah its a strange request, Right now I have 154 layers with 100s of objects on some layers. all requiring the same name. would take forever naming a layer than naming all the objects on that layer.
Hey Andrew
Thats sound strange to me... For example, the default layer has preserved name "0", and if you have 20 objects inside that layer, you wan to rename all of them to "0"? I never will do that, but never mind...
How to work with layers is very well explained in the mxs docs, however, I not see any way to catch which layer is selected. You can use
layer.ONproperty instead of selection. If that applicable, try this very lightly modification of the code example in the help file:my recent MAXScripts RSS (archive here)