[Closed] Rename objects from applied texture
Hey there. I’m trying to make a script that will rename my selected objects to it’s currently applied texture, assuming it has a standard material.
( for obj in selection do
(obj.name = obj.material.diffuseMap.filename)
)
This however, even though it works, will include the whole directory path and extension into the naming, and I can’t figure out a way to exclude it or to get rid of it automatically with the trimleft and trimright functions (trims don’t recognize slashes as far as I’m aware).
So in a way, I want the name to be: “imagename” instead of “C:/Users/MyName/etc/imagename.jpg”.
for obj in selection do
(
obj.name = getFilenameFile obj.material.diffuseMap.filename
)
Do note though, if you have two or more objects with the same texture applied, then you’ll have two objects named the same after your process, which is generally a bad thing. Just something to consider.
- Neil
Thanks a lot, both of you. In my specific case it won’t be much of a problem, but thanks for the tip.