SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.


SM Forums / Maya Questions / Programming / Error: Cannot convert data type float to type float

Programming MEL Scripts, Expressions & Programming Related Topics

Join the conversation. Reply to post
 
Thread Tools
11-07-2014, 02:50 PM   #1
baguzie2
bca
 
baguzie2's Avatar
 
Join Date: Jul 2014
Location: Austin, Texas
Posts: 9
Error: Cannot convert data type float to type float
This is a script for cloning a tank tread. I got it from a tutorial but applying it on different model. I tried to make sure that names of the elements in the rig are exactly the same with the tutorial model. But when I run it I get this error message: "Cannot convert data type float to type float". I simply stuck as I do have knowledge of scripting. I really need help please.

////Tread Cloning Tool////
//Instructions: select inital tread and run code!

///First, find width of tread and length of curve///

//Get selection...
string $sel_srcTread[] = `ls -sl`;
//Find selection's shape node...
string $shp_sel_o[] = `listRelatives -type shape $sel_srcTread[0]`;
//Use tread's bounding box to find its width...
float $tread_bbs = `getAttr ($shp_sel_o[0] + ".boundingBoxSizeX")`;
//Get length of path curve...
float $cLen = `getAttr cInfo_r_treads01.arcLength`;
//This will help us to populate our path with enough treads....
float $trd_quantity = ($cLen / $tread_bbs) - 1;


///Next, evenly space each created tread along its path///

//Calculate difference between the total tread length and the curve length...
float $size_of_gap = ($cLen % $tread_bbs);
//This finds each tread's offset...
float $each_trd_offset = $size_of_gap / $trd_quantity ;
//Each tread needs to take up this much space...
float $each_trd_spacing = $tread_bbs + $each_trd_offset;

///Finally, create a for loop to generate and constrain each tread///

//$i = our cloning range...
for ($i = 1; $i <= $trd_quantity; $i++) {
//Instance each tread and rename with prefix "dup_" to keep track of clones...
string $this_tread[] = `instance -lf -n ("dup_" + $sel_srcTread[0]) $sel_srcTread[0]`;
//Path constrain each tread to a defined path...
string $this_path = `pathAnimation -n ("mPath_" + $this_tread[0]) -fractionMode true -follow true -followAxis x -upAxis y -worldUpType "object" -worldUpObject "locUpVct_r_treads01" -inverseUp true -inverseFront false -bank false -c "cPath_r_treads01" $this_tread[0]`;
//Remove all animation nodes from cloned treads so we can control each motion path's "uValue"...
select ($this_path + "_uValue"); doDelete;
// This evenly places every tread in 0...1 space to match motion path's 0...1 space...
float $trd_spacing = ($each_trd_spacing * $i) / $cLen;
//Variable "$this_expression" holds the expression needed to drive each tread...
string $this_expression = ( "float $u = (((cPath_r_treads01.tz * anim_r_treads01.active + anim_r_treads01.offset) * anim_transport_global01.scaleY)/cInfo_r_treads01.arcLength);" + "\n" + $this_path + ".u" + " = ( 1 + ( " + $trd_spacing + " + (1-($u))%1))%1;" ) ;
//This creates the expression needed for each tread...
expression -n ($this_path + "_expr") -s $this_expression;
}
  Reply with quote
11-07-2014, 09:03 PM   #2
Gen
Super Moderator
 
Gen's Avatar
 
Join Date: Dec 2006
Location: South FL
Posts: 3,514
What line in the error on?
__________________
- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
  Reply with quote
11-07-2014, 11:49 PM   #3
baguzie2
bca
 
baguzie2's Avatar
 
Join Date: Jul 2014
Location: Austin, Texas
Posts: 9
Line 11

float $tread_bbs = `getAttr ($shp_sel_o[0] + ".boundingBoxSizeX")`;
  Reply with quote
12-07-2014, 05:19 AM   #4
Gen
Super Moderator
 
Gen's Avatar
 
Join Date: Dec 2006
Location: South FL
Posts: 3,514
I've run the code up until line 11 and got a returned value of 1, no errors. The only errors I've gotten have to do with missing objects since the only object in my scene is pCube1. Also, is there a reason behind the object names being hardcoded into this script?
__________________
- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
  Reply with quote
12-07-2014, 03:14 PM   #5
baguzie2
bca
 
baguzie2's Avatar
 
Join Date: Jul 2014
Location: Austin, Texas
Posts: 9
I do not know the object names are barcoded into the script. As I said, I got this from a tutorial. I don't have good knowledge of scripting.
Is there any way I can get to work?
Thanks
  Reply with quote
12-07-2014, 09:26 PM   #6
Gen
Super Moderator
 
Gen's Avatar
 
Join Date: Dec 2006
Location: South FL
Posts: 3,514
Maybe it can work. Could you upload the scene file? This script is calling for specific objects. I've had problems with many lines in the script but not line 11.

line 13

Code:
float $cLen = `getAttr cInfo_r_treads01.arcLength`;
This is my first bump in the road. Hardcoding object names into scripts is bad because if any of these objects is missing, it fails. It's also diminishes user friendliness and flexibility. I think the script should handle the creation and connection of the curveInfo node.


line 34

Code:
string $this_path = `pathAnimation -n ("mPath_" + $this_tread[0]) -fractionMode true -follow true 
-followAxis x -upAxis y -worldUpType "object" -worldUpObject "locUpVct_r_treads01" -inverseUp true 
-inverseFront false -bank false -c "cPath_r_treads01" $this_tread[0]`;
I don't know what "locUpVct_r_treads01" is, I had to make a guess and create a locator with that name(which the script should also handle). Same thing with "cPath_r_treads01". Given the command and flag, I guess it's a curve in the scene. This variable should have been extracted from a user selection. For example, have the user select the tread to be duplicated then the curve. The tread variable is assigned to the first object in the array and the curve variable the second.

Code:
string $selection[] = `ls -sl`;

string $treadObj = $selection[0];
string $curve = $selection[1];
line 40

Code:
string $this_expression = ( "float $u = (((cPath_r_treads01.tz * anim_r_treads01.active + anim_r_treads01.offset) * anim_transport_global01.scaleY)/cInfo_r_treads01.arcLength);" 
+ "\n" + $this_path + ".u" + " = ( 1 + ( " + $trd_spacing + " + (1-($u))%1))%1;" ) ;
Vague variable names aside, I have no clue what cPath_r_treads01.tz, anim_r_treads01.active, anim_r_treads01.offset, anim_transport_global01.scaleY are and I can't Sherlock Holmes this any further lol. I'm going to need a scene file with the proper objects in it.
__________________
- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
  Reply with quote
13-07-2014, 03:30 AM   #7
baguzie2
bca
 
baguzie2's Avatar
 
Join Date: Jul 2014
Location: Austin, Texas
Posts: 9
the system is not allowing me to upload a file. Is there any other way I can send it to you? would e-mail work?
Thanks again for helping me.
  Reply with quote
13-07-2014, 09:36 AM   #8
Gen
Super Moderator
 
Gen's Avatar
 
Join Date: Dec 2006
Location: South FL
Posts: 3,514
Yeah, that's fine.
__________________
- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
  Reply with quote
13-07-2014, 10:53 PM   #9
baguzie2
bca
 
baguzie2's Avatar
 
Join Date: Jul 2014
Location: Austin, Texas
Posts: 9
You can send me a mail so that I get get yours and send the file. Or you can give it on this forum. Thanks

Last edited by baguzie2; 14-07-2014 at 05:06 PM.
  Reply with quote
14-07-2014, 10:44 AM   #10
Gen
Super Moderator
 
Gen's Avatar
 
Join Date: Dec 2006
Location: South FL
Posts: 3,514
You can take your email down(personally I would). Upload the file to a third party file hosting site(dropbox, google drive, whatever) and use SimplyMaya's private message system to send me a link.
__________________
- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
  Reply with quote
15-07-2014, 12:42 PM   #11
Gen
Super Moderator
 
Gen's Avatar
 
Join Date: Dec 2006
Location: South FL
Posts: 3,514
The error you were getting on line 11 was actually:

Code:
Cannot convert data of type float[] to type float
The square brackets were missing from your original question and that confused me quite a bit. The error means that whatever you're trying to query returns a list of values and needs to be stored in an array. Easy solution for that.

Code:
/* Turn the original float var into a float array 
 with a slightly altered name.
 Declare a new float with the original name so you don't have to
 alter the variable in the rest of the script.
 Assign the variable a value from the list, I just chose the first one.

*/
float $tread_bbs1[] = `getAttr ($shp_sel_o[0] + ".boundingBoxSizeX")`;
float $tread_bbs = $tread_bbs1[0];
Then there is the issue of the expression complaining about cPath_r_treads01.tz, anim_r_treads01.active(there's a typo, the 'a' in active needs to be upper case) and anim_r_treads01.offset. Maya didn't know what to do with these three so I had to get the attribute values, the `` evaluates the enclosed command and returns a usable value.

Code:
string $this_expression = ( "float $u = (((`getAttr cPath_r_treads01.tz` * `getAttr anim_r_treads01.Active` + `getAttr anim_r_treads01.offset`) * anim_transport_global01.scaleY)/cInfo_r_treads01.arcLength);" + "\n" + $this_path + ".u" + " = ( 1 + ( " + $trd_spacing + " + (1-($u))%1))%1;" ) ;
It works.



Download
tankThreadGenerator
__________________
- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
  Reply with quote
15-07-2014, 11:49 PM   #12
baguzie2
bca
 
baguzie2's Avatar
 
Join Date: Jul 2014
Location: Austin, Texas
Posts: 9
thanks greatly Gen. you are a genius. it works.
  Reply with quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in render digitalone Lighting & Rendering 13 25-07-2014 11:01 AM
MEL script float problem?? Jouri Maya Basics & Newbie Lounge 5 20-11-2011 06:32 PM
BennyK - Summer Challenge BennyK Previous Challenges (Archives) 136 11-09-2008 12:18 AM
Error: Cannot convert data of type int[] to type int. pankeriste Maya Basics & Newbie Lounge 4 01-08-2006 02:47 PM
Error: Cannot convert data of type int[] to type int. pankeriste Maya Basics & Newbie Lounge 1 24-05-2005 09:38 PM