[MEL] search string variable OR Tokenize the quote character (")

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  03 March 2012
[MEL] search string variable OR Tokenize the quote character (")

I know this is a stretch, but is there anyway that I can tokenize a " character?

if not, is there any way that I can search a string variable for a particular group of characters? I know that within maya I could search:
ls "*_RN*"

to find any node that contains "_RN" ... is there any way that I could do something like this within a string variable? what I am trying to do is pull both the path, and the reference name from the mayaAscii file.

---> In pseudo code I could get around this by:

   
   
   $path = file -rdi 1 -ns "sphere___Copy" -dr 1 -rfn "sphere___CopyRN"  "C:/Users/Will/Documents/maya/projects/default//scenes/sphere -  Copy.ma";
   
   //STEP 1//
   tokenize $path "RN" $noRN;
   (which gives me two arrays: $noRN[0] and $noRN[1] )
   ($noRN[1] would equal:	  "C:/Users/Will/Documents/maya/projects/default//scenes/sphere -  Copy.ma";"
   
   //STEP 2//
   string $pathQuote[] = strip($noRN[1]);
   (this separates the first two quotation marks)
   
   //STEP 3//
   and then I would need to reassemble everything from path[1] until (size($pathQuote) - 1) into one variable which would contain:
     string $pathSColon = "C:/Users/Will/Documents/maya/projects/default//scenes/sphere -  Copy.ma";
   
   //STEP 4//
   tokenize $pathSColon ";" $finalPath
   (this would get rid of the semicolon, and leave me with nothing but the path in quotation marks)
   
   



It just feels like a bit much for what I am trying to do... I feel like there has to be an easier way that I am unaware of...

Thank you so much!!
 
  03 March 2012
Is this what you are looking for? You simply need to escape the double quote in the tokenize command.

$str = "ab\"cd\"ef\"gh";

string $tokenized[];
tokenize $str "\"" $tokenized;

print $tokenized;
 
  03 March 2012
The best solution would be to NOT use Mel ;-)

If i understand you correctly, here's how to do this in Python

path = 'file -rdi 1 -ns "sphere___Copy" -dr 1 -rfn "sphere___CopyRN"  "C:/Users/Will/Documents/maya/projects/default//scenes/sphere -  Copy.ma";'
path = path.split('"')[-1]

'C:/Users/Will/Documents/maya/projects/default//scenes/sphere -  Copy.ma'
__________________
CaptainSam
 
  03 March 2012
Nothing wrong with MEL in this scenario:

string $str = "file -rdi 1 -ns \"sphere___Copy\" -dr 1 -rfn \"sphere___CopyRN\"  \"C:/Users/Will/Documents/maya/projects/default/scenes/sphere -  Copy.ma\"";
string $splitStr[];
tokenize $str "\"" $splitStr;
string $path = $splitStr[size($splitStr) - 1];
 
  03 March 2012
Quote: Nothing wrong with MEL in this scenario:


Except for spending 3 lines and a lot of thinking to do something that you should be able to write in one line - and read and write pretty much as fast as you read a normal sentence in English.

That's 3 lines of clunky code to introduce bugs in, with the stupid tokenize command that doesnt work the same way as mel usally does (ie, you cant write string $split[] = `tokenize $word "/"`) - AND you have to write gibberish like $splitStr[size($splitStr) - 1] instead of just splitStr[-1].

Even Python called from mel is a lot easier and more readable than any possible way of doing it in Mel only

string $path = python("'"+$path+"'").split('\"')[-1]")


Yes, you can do this in Mel, but you generally end up spending a lot of time on things that are child's play in Python, and can't do a tenth of what you can do in Python in the first place. Hence my snarky comment about not doing this in Mel
__________________
CaptainSam
 
  03 March 2012
When the question specifically states "MEL" in the title, and it is referring to a specific MEL command (e.g. tokenize), there is little point in posting a snarky reply about how Python is superior.

Yes, Python is a very powerful language, my language of choice when scripting in Maya, but it doesn't change the fact that there is a massive amount of legacy MEL code out there and knowing how to work with it effectively is still a useful skill.
 
  03 March 2012
Thank you so so much guys!!

using \" worked perfectly!! I haven't gotten into pyMel yet, I was hoping to go the C++ API route eventually, simply because I know a (tiny) bit of C++ already, and I have never used Python. Is there a big advantage to using Python over using the C++ API? Speed of writing the programs maybe?

I wanted to write a script to do this outside of maya but one of my friends at work told me that it would be better to make it something that could be a shelf button - that way it would be universal (some of my coworkers use Macs at home), and it would be one less program to keep track of.

I am so sorry about the late reply, I was moving my girlfriend in this weekend . Thank you so much!!
 
  03 March 2012
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 11:30 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.