tokenize giving error on first run

Become a member of the CGSociety

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

Thread Tools Display Modes
  04 April 2003
Question tokenize giving error on first run

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?
  04 April 2003
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
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
hey thanks for pointing me in the right direction guys, it was indeed to do with the $material string declaration

  01 January 2006
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 10:27 AM.

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