PDA

View Full Version : stringArrayIntersector


ktpr
02-25-2004, 05:24 AM
stringArrayIntersector should work but I'm getting some mighty weird errors. Stick this code in your mel box and tell me what's wrong:

---

string $arrayIntersector;

string $string1[] = {"ktpr", "is", "testing", "this"};

string $string2[] = {"ktpr", "is", "testing", "this", "junk5", "junk6", "junk7", "junk8"};


stringArrayIntersector -edit -intersect $string1 $arrayIntersector;
stringArrayIntersector -edit -intersect $string2 $arrayIntersector;
string $results = `stringArrayIntersector -query $arrayIntersector`;

print("these are the results " + $results);

// Error: line 8: //

I'd hate to have to do string array intersecting in MEL where's theres already a function for it. I'm using Maya 4.5 Complete

macaroniKazoo
02-25-2004, 05:46 AM
string $arrayIntersector = 'stringArrayIntersector';

you need to actually create the string intersector object. its a weird one, because this is a UI object that does the intersection, NOT a mel command. its very strange, but yeah. thats how it works.

so the above line creates the string intersector UI object.

also, because its an _array_ intersector, it returns an array, so your line:

string $results = `stringArrayIntersector -query $arrayIntersector`;

should read:

string $results[] = `stringArrayIntersector -query $arrayIntersector`;

and your print line won't work, because you can't add arrays to strings. just a print $results; will work tho.

ktpr
02-25-2004, 06:03 AM
Interesting. My friend also found that the -edit -reset flags were needed to make the example work. This is the working example I have:

string $myIntersector;

string $initialArray[] = {"Excellent", "Smithers", "doh"};

stringArrayIntersector -edit -reset $myIntersector;
stringArrayIntersector -edit -intersect $initialArray $myIntersector;
stringArrayIntersector -edit -intersect {"Smithers", "Homer"} $myIntersector;

string $foo[] = `stringArrayIntersector -query $myIntersector`;

stringArrayIntersector -edit -reset $myIntersector;

for($node in $foo){ print("\n " + $node);}

---
I foudn that if i didn't have that second -edit -reset in there the insector would complain about the insector object name not being unique. I didn't know this was a global value.

macaroniKazoo
02-25-2004, 06:06 AM
it probably isn't. I expect you ran the example from the mel docs, which also uses the variable $myIntersector - which created it as a global variable.

try restarting maya, and I expect you'll find that the variable $myIntersector isn't defined. just remember to delete your UI when you're done.

PS i've actually made a script which calls the string intersector, does the intersection, deletes the intersector object, then returns the results. which means I can do an array intersection in a single, neat line of code. You might want to do the same - just for the sake of simplicity.

ktpr
02-25-2004, 06:11 AM
You're right, it didn't matter after the second run. The state of the intersector doesn't seem to be consistent to me. This is the weirdest mel function I've come across yet. Anwya, how do I delete the intersector when I done with it? delete $myIntersector doesn't work.

Thanks for your time.

macaroniKazoo
02-25-2004, 08:57 PM
remember, its a UI object, not a normal object.

so deleteUI $arrayIntersector; is what you're after. and you're right, it is very weird indeed. why alias didn't implement it as a normal mel command is a little beyond me, but hey... :)

CGTalk Moderation
01-17-2006, 01:00 PM
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.