Sign in to follow this  
Holland

Maya API question...

Recommended Posts

I'm not sure if this is the appropriate place to ask this, but I hope it's simple enough that someone here can answer it. I'm working on my model and animation exporter for Maya (2008 version if that matters). Basically...all I'm trying to do is pull out the file name from the MFileObject, but I want it without any path or extension. For example, I have a file called Anim1.bin I want to just pull "Anim1" from this. I've tried Name() FullName() RawName() ResolvedName() and a few other functions in the MFileObject class. They are all returning the exact same thing, "Anim1.bin". For now I'm just going to tokenize the string by the '.' and handle it that way, but is there ANY way to have the MFileObject give me the name sans extension? Thanks a lot ladies and gents! -Trevor

Share this post


Link to post
Share on other sites
Hi Trevor,

I think you need to use the split method of MString

I.e.
// Original filename
MString fullFilename = "TestFile.ext";
// Destination filename
MString filename;
// Array of split strings
MStringArray splitFilename;
// Split up original string into bits seperated by '.' character
MStatus stat = fullFilename.split('.', splitFilename);
if(stat == MStatus::kSuccess)
{
// get the length of the last string in the array (the file extension)
unsigned int extLen = splitFilename[splitFilename.length()-1];
if(extLen > 0)
{
// Get the substring of the original filename (chopping off extension
// note the minus 1 because of '.' character
filename = fullFilename.substringW(0,fullFilename.length()-extLen-1);
}
}

Or something like that anyway, I've not tested it, just typed it straight into here so there could be some errors. But I've done similar before so the general approach works.

You might want to try it with a few different test strings to make sure. I.e with full paths and strings with lots of '.' characters in them or without extensions to make sure it doesn't chop off too much.

Cheers, Dan

Share this post


Link to post
Share on other sites
Opps didn't notice you say tokenize, my solution might not be news to you then. Sorry not sure of a better method.

Share this post


Link to post
Share on other sites
Sorry it took so long for me to reply and thanks for the response! Your solution isn't much different than using the string's tokenize function, but I prefer to do it the way you mentioned. I like the idea of sticking with the Maya API as much as possible, so your solution is great! Thanks so much.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this