Get maya file name

Get maya file name

vuhoangtuandct
Explorer Explorer
3,465 Views
4 Replies
Message 1 of 5

Get maya file name

vuhoangtuandct
Explorer
Explorer

Hi everyone. I'm looking for a way to get maya scence name and maya folder name that contain that scene (mel or python is ok. Because I'm working in the studio so i can't use any plugin outside)

 

Example my maya scene name is Buidling.0001.mb since i'm using increasement and save. I want to extract the name Building only, don't include .0001

If this way cannot archive or impossible. Can I get the folder name that contain this scene

0 Likes
Accepted solutions (1)
3,466 Views
4 Replies
Replies (4)
Message 2 of 5

Kahylan
Advisor
Advisor

Hi!

 

You can use the file command to get your full file path and then just edit the strings to what you want.

 

import maya.cmds as mc

sceneNameLong = mc.file(q= True, sn= True)

splitName = sceneNameLong.split("/")
folder = splitName[-2]
sceneName = splitName[-1].split(".")[0]

 

Now this only works if the name you want doesn't contain "." because that would be split as well. So for example New.Building.0001.mb, would just give you "New" as the scene name.
But since generally using periods in filenames for anything but increments is viewed as bad practice, so I don't think this is a huge issue.

 

I hope it helps!

 

Message 3 of 5

vuhoangtuandct
Explorer
Explorer

Thank you so much !

Message 4 of 5

Kahylan
Advisor
Advisor
Accepted solution

If my answer was what you were looking for, please mark it as an accepted solution so other users will find it more easily in the Future 🙂

 

 

Message 5 of 5

vuhoangtuandct
Explorer
Explorer

Thanks for your help. That's help me solve the solution ! I'm grateful that got my answer