PDA

View Full Version : intToString in Maya 4??


sajeev
05-24-2003, 06:01 PM
Is there a way to convert integers to strings in Maya 4..
like the intToString command in version 4.5..what I want to do is to store my int variable say 1 as 01...2 as 02....any suggestions???

ajk48n
05-25-2003, 02:16 AM
This should work:

int $p;

string $s = ("0" + $p);

mark_wilkins
05-25-2003, 07:16 AM
are you trying to pad integers to some number of digits?

if so, you can always do something like this. (And yes, there are more elegant ways to do this that I'm sure people will come up with shortly):



global proc string fourDigitPad (int $i) {

if ($i >= 1000) {
return (string($i));
}

if ($i >= 100) {
return ("0" + string($i));
}

if ($i >= 10) {
return ("00" + string($i));
}

return ("000" + string($i));

}

-- Mark

sajeev
05-25-2003, 08:04 PM
Thanks a lot ajk48n....looks so easy...and it works!!Cooool dude.

Mark..the padding is for a timecode script.... hr:mi:se:fr...00:00:00:00:...I wanted modify and display the timecode script from highend3d as a HUD and also with the 2 digit padding..00:00:00:00 right next to the framecounter HUD.Great for character animation work(and playblasts look a lot cooler:))
Yep digging into MEL these days.Thanks to MEL Scripting for Maya Animators...Great book.Just what the doctor ordered...Thanks Mark..


Sajeev

mark_wilkins
05-25-2003, 09:32 PM
Thanks Sajeev!

Advice: make sure that the script you're adapting properly handles drop-frame timecode if you're supporting that... I've found that there's some bad code out there here and there that doesn't drop the right frame numbers correctly.

-- Mark

sajeev
05-26-2003, 07:11 PM
Mark.
Didn't understand....script you're adapting properly handles drop-frame timecode ......
Here is what I did...
I added some code to the HighEnd3d showTimeCode.mel(which uses currentTime -q to store the time)script from Ed Jackson Give him all the credit)...All I had to do was first convert the int variables to string with 2 digit padding..and...


string $timecode[];
optionVar -ca "$timecode[]";
optionVar -sva "$timecode[]" $shr -sva "$timecode[]" $smin
-sva "$timecode[]" $ssec -sva "$timecode[]" $sfrm;


then in the userSetup.mel I added the code for the HUD...

string $timecodecmd = "showTimeCode"+";"+"\n"+"optionVar
-q"+" "+"\""+"$timecode[]"+"\"";
headsUpDisplay
blah
blah
blah
-command "eval ($timecodecmd)"
HUDshowTimeCode;

works for me...but I'm posting the code to find out if there are any problems the way I've written it...

Sajeev

mark_wilkins
05-27-2003, 04:55 AM
sorry. I wasn't talking about the piece you were building -- I was saying that the script you're starting with, Ed Jackson's script, should handle drop-frame time code correctly, if that's what you're using. Anyway, you probably know all of this but others may be interested so here goes:

Drop-frame and non-drop-frame are terms that only really make sense when discussing NTSC video, the standard used in the U.S. and Japan.

For those who aren't familiar with the term, non-drop-frame time code for NTSC video assumes that there are exactly 30 frames per second. In fact, though, the frame rate is 29.97 fps.

So, drop-frame time code was invented. When assigning time code numbers to frames, a frame number is skipped here and there. *No actual video frames are ever lost in this process* so it's not a matter of doing anything to the video itself... it's just how time code numbers are assigned.

In drop-frame time code, mostly seconds roll over when the frame number goes from 29 to 00, but sometimes it rolls over when the frame number goes from 28 to 00.

The reason for drop-frame timecode is to keep the time code from drifting away from the actual time. If the numbering assumes 30 fps but the actual number of fps is 29.97, then it will take more than four hours to get to the time code 04:00:00:00 (four hours, 0 minutes, 0 seconds, 0 frames.) Drop-frame time code keeps time and time code pretty much in sync over the long run.

-- Mark

ash4640
05-15-2004, 03:32 AM
Hai Mr.Mark that was a nice explanation of drop code time.
I need a script to display
filename :
date :
time :
camera :
on a HUD how do i do that with the scarce help from mel documentation i have a idea of how to do the hud but can you pls explain in detail with the detail it will be of gr8 help Mr.Wilkins.
This is for windows system.
Ash.

strarup
05-24-2004, 08:10 PM
Hi ajk48n,

cool tip... thanx... :)

just used it to converting a float array to a string array...

a little example...

e.g. this will print out the frame numbers of the selected object...


string $daSelObjs[] = `ls -sl`;

float $flKeyList[], $flSortedKeyList[];
string $strKeylist[], $strRD_KeyList[], $stKeyListCmd[];
int $j = 0;


if(`size($daSelObjs)` < 1)
{
print("nothing selected... \n");
}
else
{

//get all the keyframes for the selected objects...
$flKeyList = `keyframe -q -timeChange $daSelObjs`;
//and sort them...
$flSortedKeyList = sort($flKeyList);
//append the keyframe float value to a string
for($j=0; $j<size($flKeyList); $j++)
{
// here the TIP is working... just add a
// double ".... :)
$strKeylist[$j] = (""+$flSortedKeyList[$j]);
}

//remove redundant keyframes from the list
//since several attributes share keys on the same
//frame numbers...
$strRD_KeyList = stringArrayRemoveDuplicates($strKeylist);

//clear the original $flKeyList[] to get the shorten list
clear $flKeyList;

//assign the string values to the float array
for($i = 0; $i < size($strRD_KeyList); $i++)
{$flKeyList[$i]= $strRD_KeyList[$i];}

print($flKeyList+"\n");
}

once again... Thanx... :)

regards

Strarup

ash4640
05-26-2004, 06:28 PM
Hai Sue with some guidance i wrote this script for creating two curves and making a nurbs loft. But their is an warning when i run it....I dont know how to declare loft as an string pls check the error you will understand can you pls corect the data type and give
error when i run it - Cannot convert data of type string[] to type string.
Start of trace: (command window: line 59).
GenerateLoft (command window: line 1).

/*
Ashwanth
Tested: Maya 4.5 Learning Edition, Win XP
Will display in view:
- Curve 1, Curve 2 and the Lofted Nurb Mesh Between Them

*/

global proc string GenerateLoft()
{
string $CreateMesh;

curve -d 3
-p -3.499096 0 -0.461121
-p -3.413971 0 -0.886549
-p -3.243722 0 -1.737406
-p -2.242109 0 -2.84242
-p -1.295978 0 -3.330527
-p -0.223164 0 -3.528058
-p 0.398401 0 -3.551815
-p 1.396289 0 -3.259258
-p 2.316626 0 -2.778243
-p 3.170844 0 -1.739888
-p 3.317346 0 -0.923543
-p 3.390597 0 -0.515371
-k 0 -k 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 9 -k 9 ;

curve -d 3
-p -4.095841 4 2.142857
-p -4.18035 4 1.748992
-p -4.349369 4 0.961262
-p -4.383719 4 0.0337941
-p -3.992788 4 -0.93369
-p -3.569178 4 -1.66974
-p -3.050572 4 -2.315019
-p -2.293632 4 -2.903821
-p -1.608535 4 -3.158306
-p -0.874398 4 -3.504547
-p -0.264579 4 -3.492584
-p 0.142479 4 -3.519693
-p 0.833904 4 -3.42322
-p 1.567113 4 -3.131006
-p 2.499813 4 -2.76885
-p 2.918264 4 -2.231209
-p 3.566732 4 -1.488955
-p 3.809383 4 -1.089645
-p 4.143297 4 0.151331
-p 4.192476 4 0.972565
-p 4.05572 4 1.644261
-p 3.987342 4 1.980108
-k 0 -k 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 -k 11 -k 12 -k 13 -k 14 -k 15 -k 16 -k 17 -k 18 -k 19 -k 19 -k 19 ;

$CreateMesh =` loft -ch 1 -u 0 -c 0 -ar 1 -d 1 -ss 5 -rn 0 -po 0 -rsn true "curve1" "curve2"`;
return $CreateMesh;
}
string $window;
$window = `window -title "Loft Generater"
-widthHeight 100 150
-menuBar off
-minimizeButton off
-maximizeButton off
-sizeable on
-titleBar on`;

columnLayout
-columnAttach "both" 1
-rowSpacing 10
-columnWidth 150;

button
-label "Create Mesh"
-command "GenerateLoft()";

//intSlider
//-min 0
//-max 100
//-value 0
//-step 10;

showWindow $window;
Pls help me guys.
Thanks.

strarup
05-27-2004, 12:37 PM
Hi Ashwanth,

this should work... :)

regards

Strarup


/*
Ashwanth
Tested: Maya 4.5 Learning Edition, Win XP
Will display in view:
- Curve 1, Curve 2 and the Lofted Nurb Mesh Between Them

*/

proc string GenerateLoft()
{
string $CreateMesh;

curve -d 3
-p -3.499096 0 -0.461121
-p -3.413971 0 -0.886549
-p -3.243722 0 -1.737406
-p -2.242109 0 -2.84242
-p -1.295978 0 -3.330527
-p -0.223164 0 -3.528058
-p 0.398401 0 -3.551815
-p 1.396289 0 -3.259258
-p 2.316626 0 -2.778243
-p 3.170844 0 -1.739888
-p 3.317346 0 -0.923543
-p 3.390597 0 -0.515371
-k 0 -k 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 9 -k 9 -n daCurve1;

curve -d 3
-p -4.095841 4 2.142857
-p -4.18035 4 1.748992
-p -4.349369 4 0.961262
-p -4.383719 4 0.0337941
-p -3.992788 4 -0.93369
-p -3.569178 4 -1.66974
-p -3.050572 4 -2.315019
-p -2.293632 4 -2.903821
-p -1.608535 4 -3.158306
-p -0.874398 4 -3.504547
-p -0.264579 4 -3.492584
-p 0.142479 4 -3.519693
-p 0.833904 4 -3.42322
-p 1.567113 4 -3.131006
-p 2.499813 4 -2.76885
-p 2.918264 4 -2.231209
-p 3.566732 4 -1.488955
-p 3.809383 4 -1.089645
-p 4.143297 4 0.151331
-p 4.192476 4 0.972565
-p 4.05572 4 1.644261
-p 3.987342 4 1.980108
-k 0 -k 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 -k 11 -k 12 -k 13 -k 14 -k 15 -k 16 -k 17 -k 18 -k 19 -k 19 -k 19 -n daCurve2;

$CreateMesh = "loft -ch 1 -u 0 -c 0 -ar 1 -d 1 -ss 5 -rn 0 -po 0 -rsn true \"daCurve1\" \"daCurve2\"";
return $CreateMesh;
}
string $window;
$window = `window -title "Loft Generater"
-widthHeight 100 150
-menuBar off
-minimizeButton off
-maximizeButton off
-sizeable on
-titleBar on`;

columnLayout
-columnAttach "both" 1
-rowSpacing 10
-columnWidth 150;

button
-label "Create Mesh"
-command "eval(`GenerateLoft`);";

//intSlider
//-min 0
//-max 100
//-value 0
//-step 10;

showWindow $window;

CGTalk Moderation
01-15-2006, 06: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.