View Full Version : tokenize giving error on first run

04 April 2003, 07:23 PM
hi all,

i've got this bit of code to return the matrial of a selected object and then make it semi transparent. it works...apart from the first time i run it..i get this error

// Error: Invalid call to "tokenize". Check number and types of arguments expected by the procedure. //

but then if i run it straight after, it all works fine.

here is the code, try it yourself.

$sel = `ls -flatten -sl `;
$setArray = `listSets -type 1 -ets -o $sel`;
$material = `connectionInfo -sfd ($setArray[0] + ".surfaceShader")`;
string $buffer[];
tokenize $material "." $buffer;

print ($material+"\n");
print ($buffer[0]+"\n");
$selmat = $buffer[0]+".transparency";
print $selmat;
setAttr $selmat -type double3 0.5 0.5 0.5 ;

just select an object with a material assigned to it, and it should make it 50% transparent.

i cant see what is wrong with the way i have used tokenize, i have tried it several other ways also, but always get the same error. could it be somethign to do with not being inside a global procedure? :shrug:

04 April 2003, 08:14 PM
the tokenize command worked fine here. Maybe check that you actually have anything in your $material string the first time you run

04 April 2003, 08:17 PM
Off the top of my head, I think the problem is more likely to be with the kind of data you are feeding it. ConnectionInfo can return boolean, string and stringArray so I would check to see what's in your $material var when the script fails.

Note that in the code you posted, you did not explicitly declare $material as a string, so it can take on any datatype that connectionInfo returns, which is probably misdirecting you to think that the problem lies with the tokenize command.


04 April 2003, 09:26 PM
hey thanks for pointing me in the right direction guys, it was indeed to do with the $material string declaration

cheers :thumbsup:

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