[HELP] Catagorizing unknown objects into strings by naming conventions (MEL)

Become a member of the CGSociety

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

Thread Tools Search this Thread Display Modes
  10 October 2012
[HELP] Catagorizing unknown objects into strings by naming conventions (MEL)

Hi all,

I was hoping someone can help me work out how to tackle this in MEL.

Ive got a bunch of files. In each file is a bunch of models using this naming convention...


Where red is constant within each file (but not between files), dark green is a number between 000 and 999, and blue is either "Hi" "Lo" or "Col"

I can easily get the content of red as a string by deconstructing the name of the file (using this in another script) but am unsure how to go about tackling this problem.

Basically im hoping for this sort of thing. Say in my file I have the following...

Quote: OBJ_Fishing_Rod_m001_p001_Hi

I want to be able to have...


Without necessarily knowing the content of the file (apart from that it will follow these conventions)

As you may have guessed im pretty new to MEL so sorry if im being kind of needy here. Ive learnt a lot in the past few weeks but this seems to be over my head and is pretty much the basis for everything i want to do with this project.

Thanks everyone for your time.
  10 October 2012
Looks like you want to be able to have string variables generated automatically holding the object names? Although its possible using such a weird command like eval ("global string $p001_Hi = \"OBJ_Fishing_Rod_m001_p001_Hi\"") i would avoid such a thing. If you want to get a pointer to an existing object you could query if a object exists with an name ending like "p001_Hi" and in the same run get its full dag path name:
string $obj[] = `ls -long "*p001_Hi"`;
then query the size of the array:
int $numObj = `size $obj`;
if the size == 1 you got it, if the array carries more elements you would need to specify your ls command.
  10 October 2012
How are you planning to use those variables if they're created dynamically? There's no real way you can call those variable "automatically" without typing them out in MEL that I'm aware of. In Python you can kinda do that, but it looks quite ugly

var()[ "p001_Hi" ]

or you can use string variable

myName = "p001_Hi"
var()[ myName ]

So now it's a matter of splitting your text into 2 pieces. Assuming your file name is consistent (meaning they always have _p follow by 3 numbers) that could easily be done using re.

 import re
 # For example if you store those names in a list
 files = [  "OBJ_Fishing_Rod_m001_p001_Hi", 	"OBJ_Fishing_Rod_m001_p001_Lo",
 for f in files:
  	    for match in re.finditer("p\d\d\d", f ):
		        vars()[ f[match.span()[0]:] ] = "test"
 		 # give it "test" for the purpose of testing

And there you have it.

# Result: test #

# Result: test #

  10 October 2012
Thats better done with python, i agree. But yet you could dynamically address MEL strings even if you dont know if they exist, of course only if you dont mind tinting your executers response field into deep red, works nonetheless

  //somewhere a proc decided to create global strings populated with values
  string $strSuffix = "$strName_";
  int $strRange[] = {0,10};
  	int $rand = rand($strRange[0],$strRange[1]);
  	eval("global string " + $strSuffix + $rand + " = \"pineapple\"");
  // this proc returns the content of a string
  global proc string returnStringValue(string $globalString)
  	return $globalString;
  // take the string from the procedure and put it in an additional global string variable
  global proc catchStringValue(string $strName)
  	global string $handOver;
  	$handOver = returnStringValue($strName);
  // call both procs above but catch the result to be able to go on
  global proc string getStringValue(string $strName)
  	global string $handOver;
  	string $cmd = "catchStringValue(returnStringValue(" + $strName + "))";
  	int $res = catch(eval($cmd));
  	return $res ? "" : $handOver;
  string $result = "";
  	string $tmp = getStringValue(($strSuffix + $i)); //whoops
  	$result += ("$strName_" + $i + ": " + $tmp + "\n");
  print("go on \n");

Last edited by zaskar : 10 October 2012 at 02:37 PM.
  10 October 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
Society of Digital Artists

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

All times are GMT. The time now is 01:11 AM.

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