[MEL] casting string array to float

[MEL] casting string array to float

Anonymous
Not applicable
1,783 Views
7 Replies
Message 1 of 8

[MEL] casting string array to float

Anonymous
Not applicable

Hi 

I having a trouble with a code.

I want to create a new expression  into a default value  of a  Arnold aiUserDataInt 

I need the default value of a aiUserDataInt = attribute frome a geometry that I crate name "ID"

so, my code looks like this:

 

string $Selected[] = `ls -selection`;

for ($node in $Selected)

aiUserDataInt1.default = $Selected.id;

 

but I have these error:

// Error: Line 2.37: Cannot cast data of type string[] to float. //

so, I suppose default value do not accept arrays

my question would be: is there a way to convert array into float?

or what am I doing wrong?

 

Tnks in advance

 

0 Likes
1,784 Views
7 Replies
Replies (7)
Message 2 of 8

absoluteKelvin
Collaborator
Collaborator
aiUserDataInt1.default = $Selected.id;

Should be
aiUserDataInt1.default = $node.id;
https://www.artstation.com/kelvintam
0 Likes
Message 3 of 8

Anonymous
Not applicable
not working

// Error: aiUserDataInt1.default = $node.id; //
// Error: Line 2.33: Syntax error //
0 Likes
Message 4 of 8

absoluteKelvin
Collaborator
Collaborator

opps sorry my bad.

try

 

replace with

aiUserDataInt1.default = ($node + ".id");

 

https://www.artstation.com/kelvintam
Message 5 of 8

Anonymous
Not applicable
hi
hey! that actualy works, but the default value stucks at 0
// Warning: line 2: Converting string "aiSwitch1.id" to a float value of 0. //
sorry I'm a newbie programing and I'm very grateful for you'r Help
0 Likes
Message 6 of 8

absoluteKelvin
Collaborator
Collaborator

what is this script suppose to do?

 

are you using this in the expression editor or script editor?

https://www.artstation.com/kelvintam
Message 7 of 8

Anonymous
Not applicable

the script tempt to create a material ID for shading in arnold.

I created an script for geometry, named ID, this script put an attibute and show it in the channel box, you can put any number betwen 0 to 100.

But I need to create a relation ship betwen the attribute ID and material of arnold in this case the aiSwitch.

The aiSwitch its a arnold shader that you can conect any  shader to the slots and it has an index value, depends of the number that you put in the index value, is the shader that applys in the geometry, so I used a aiUserDataInt (wich its a node tha only provides an attibute default value, a number) and i was trying to make an expresion in the default vale, that would be like: aiUserDataInt1.default = ID of the geometry.

then just conect the aiUserDataInt to the index value of the aiSwitch.

the goal for thes scrip is: conect several shader to the aiSwitch an depend of the Id of the geometry is the shader that applys in the geometry

i hope I was clear abot the funtion of the script

0 Likes
Message 8 of 8

mcw0
Advisor
Advisor

Instead of the expression, why not just directly connect your ID attribute to the switch?

0 Likes