Integrating 3D models with photography
Interested in integrating your 3D work with the real world? This might help
# 1 11-07-2014 , 02:50 PM
baguzie2's Avatar
bca
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;
}

# 2 11-07-2014 , 09:03 PM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
What line in the error on?


- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
# 3 11-07-2014 , 11:49 PM
baguzie2's Avatar
bca
Join Date: Jul 2014
Location: Austin, Texas
Posts: 9
Line 11

float $tread_bbs = `getAttr ($shp_sel_o[0] + ".boundingBoxSizeX")`;

# 4 12-07-2014 , 05:19 AM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
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 ||::
# 5 12-07-2014 , 03:14 PM
baguzie2's Avatar
bca
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

# 6 12-07-2014 , 09:26 PM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
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 ||::
# 7 13-07-2014 , 03:30 AM
baguzie2's Avatar
bca
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.

# 8 13-07-2014 , 09:36 AM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
Yeah, that's fine.


- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
# 9 13-07-2014 , 10:53 PM
baguzie2's Avatar
bca
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.
# 10 14-07-2014 , 10:44 AM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
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 ||::
# 11 15-07-2014 , 12:42 PM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
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.

user added image

Download
tankThreadGenerator


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

Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads