Rename layers

Rename layers

malcomarmstrong
Advocate Advocate
2,856 Views
6 Replies
Message 1 of 7

Rename layers

malcomarmstrong
Advocate
Advocate

Anyone tell me why the following does not work? It returns ok but layers are not renamed. 

fn layerNamesToLowerCase = 
(
    for k = 1 to layerManager.count-1 do
    (	
aLayer = layerManager.getLayer k layName = toLower(aLayer.name) print layName aLayer.setName layName ) ) layerNamesToLowerCase()

--feedback in listener
layerNamesToLowerCase()
<MixinInterface:LayerProperties>
"layer003"
<MixinInterface:LayerProperties>
"layer001"
<MixinInterface:LayerProperties>
"layer002"
OK

If i just get a layer thus: 

(layerManager.getLayer 2).setName "Numpty"

it works fine, so why is the function not doing this?

0 Likes
Accepted solutions (1)
2,857 Views
6 Replies
Replies (6)
Message 2 of 7

malcomarmstrong
Advocate
Advocate

I also cast the single use example to a var and it works:

 

der = "fat_plums"

(layerManager.getLayer 1).setName der

But this doesn`t, returns false:

der = toLower((layerManager.getLayer 1).name)
derp = (layerManager.getLayer 1)
derp.setName der

 

0 Likes
Message 3 of 7

Swordslayer
Advisor
Advisor

Layer's unique identifier is still it's name, case-insensitive. The case-insensitive part is important here, it means that trying to assign lowercased name will return false as it's treated as if it was the same name. So first rename to something temporary and then set the lowercase name and it will work.

Message 4 of 7

malcomarmstrong
Advocate
Advocate
Accepted solution

I knew about the case sensitive part, but always felt that it was wrong to have that. Renaming it temporarily and then back again is bloated code that does not really need to be there, but if its the only way in Maxscript, so be it. I will probably just do it with python then where the strings will be case sensitive. Should have thought of that before, but its part of a larger maxscript tool, which I did not want to have to trawl thorough to rewrite as python.

 

Thanks

0 Likes
Message 5 of 7

malcomarmstrong
Advocate
Advocate

Actually, that may not work either as I will still get a list of strings that Max will not change. Ah, dammit. Temp rename it is then

0 Likes
Message 6 of 7

Swordslayer
Advisor
Advisor

@malcomarmstrong wrote:

Renaming it temporarily and then back again is bloated code that does not really need to be there, but if its the only way in Maxscript, so be it. I will probably just do it with python then where the strings will be case sensitive.


Nothing to do with maxscript (btw. given the choice, the python wrapper will almost always be slower anyway), everything to do with core decisions made in the last century. Also, the unique name per layer is one of the things that prevents nested layers to be fully used since you cannot have nested layers with identical names either... And it's a one-line difference anyway, no reason to avoid that 🙂

Message 7 of 7

Radush
Contributor
Contributor

Dear friend, perhaps you can help me too, in my opinion the task is simple but the answer is nowhere to be found (
I have code that creates a new layer in tab Toggle Scene Explorer


LayerManager.newLayerFromName "Layer_A"

below is the code that creates the object

Box pos:[0,0,0] isSelected:on width:2 length:2 height:2

 

The Box object is located in the selected layer by default, but I want it to be located in the layer "Layer_A"

0 Likes