PDA

View Full Version : concatenate int arrays?


diskhub
01-31-2007, 01:17 AM
how do i join these 2 int array together?
int $array1[]={1,2,3,4,5};

int $array2[]={11,12,13,14,15};

Adam
01-31-2007, 05:32 AM
I think this is what you want



int $array1[]={1,2,3,4,5};
int $array2[]={11,12,13,14,15};

int $array3[];
for ($item1 in $array1)
{
$array3[size($array3)] = $item1;
}
for ($item2 in $array2)
{
$array3[size($array3)] = $item2;
}
print $array3;




There is a Catenate command in maya but it only works on strings and although you could convert your int arrays to string arrays and then use it to combine the two into one string array it seems easier to just do it manually since it is relatively simple.

Chirieac
01-31-2007, 05:52 AM
1. Join array2 in array1:


//declare variables
int $sArr = size($array1);
int $i = $sArr;

//start join
for ($each in $array2) //because array2 is bigger
{
$array1[$i] = $array2[$i-$sArr];
$i++;
}




2. Join array1 & array2 in array3:


//declare variables
int $array3[];
int $sArr1 = size($array1);
int $sArr2 = size($array2);
int $sArr3 = $sArr1 + $sArr2
int $i;

//start join
for ($i = 0; $i < $sArr3; $i++)
{
if ($i < $sArr1)
$array3[$i] = $array1[$i];
else
$array3[$i] = $array2[$i-$sArr1];
}

StephG
01-31-2007, 07:34 AM
I'll bite:


global proc int[] catenateIntArray(int $array1[], int $array2[])
{
int $array3[] = $array1;
for ($a in $array2)
{
$array3[`size $array3`] = $a;
}
return $array3;
}
int $array1[]={1,2,3,4,5};
int $array2[]={11,12,13,14,15};
catenateIntArray $array1 $array2;

diskhub
01-31-2007, 08:08 AM
ok, i still have not solve my problem...

I am trying to pop in int values into int array easily...
Is there anyway to solve the following problem:
I have rendered some files in Maya but there are alot of missing frame.
Following is an example of how the missing frames look like...

1-10, 15, 18, 20-44, 50, 52, 56, 100-300...

I wish to write a mel to put these frame nos into an array, so that it looks like the following.:
int $array[] = {1,2,3,4,5,6,7,8,9,10,15,18,20,21,22,23....44,50,52,56,100,101,102...300}

how do i come about solving this? anyone?

Chirieac
01-31-2007, 09:14 AM
global proc rangeToArray(int $array[], int $startNr, int $endNr)
{
while ($startNr < = $endNr)
{
$array[size($array)] = $startNr;
$startNr++;
}
}


Now run this script and enter "rangeToArray (your array, startNr, endNr)";
Ex:
int $frames[];
rangeToArray ($frames, 1, 10,);
Your array it will be: $frames[] = {1,2,3,4,5,6,7,8,9,10};

Now enter this: rangeToArray ($frames, 100, 300);
End the array will be: $frames[] = {1,2,3,4,5,6,7,8,9,10.100,101,...,300};

If you have only a nr. enter this: rangeToArray ($frames, 15, 15);

StephG
01-31-2007, 04:09 PM
ok, i still have not solve my problem...

1-10, 15, 18, 20-44, 50, 52, 56, 100-300...

I wish to write a mel to put these frame nos into an array, so that it looks like the following.:
int $array[] = {1,2,3,4,5,6,7,8,9,10,15,18,20,21,22,23....44,50,52,56,100,101,102...300}

how do i come about solving this? anyone?

OK, it seems like you are looking to present things a cerain way to get results.

So how about this: write down exactly how you would like to enter those missing frames to get the results.

In your example, are you going to have 8 separate arrays, in numerical order?
Will they be in an arbitrary order?
How are the arrays being created?
Why aren't the missing frames all being put into a single array in the first place?

(maybe the script you really want is one that will look at a directory and find the missing frames, or frames that have been moved or deleted because they had a problem, put them in an array and automatically set out to render them)

Chirieac
01-31-2007, 04:19 PM
1-10, 15, 18, 20-44, 50, 52, 56, 100-300...

If I get'it right, this is what you want:

string $missingFrames = "1-10,15,18,20-24,50,52,56,100-300";
int $array[] = cRangeTokenize ($missingFrames);
//result: $array = {1,2,3,...,10,15,18,20,...,24,50,52,56,100,101,...,300}

cRangeTokenize is a script that I created for you, diskhub.

diskhub
02-02-2007, 12:10 AM
Hi, thanks Chris...
I have overlooked the possibilities of solving in ur method...

Thanks.

However, i seem to have another problem,
I realised that the Batch Render doesn't do like what i wan to do.
I actually thinking of rendering those missing frames (in the array) using such proc...

global proc renderBadFrames(int $array[])
{
int $i;
for($i in $array)
{
setAttr "defaultRenderGlobals.startFrame" $i;
setAttr "defaultRenderGlobals.endFrame" $i;
BatchRender;
}
}


Cos if i do that, the BatchRender tends to behave in a strange way... anyone knows how to solve this BatchRender problem? My ultimate goal is to render those long missing frames on a machine in some Batch Mode...

Please advise

CGTalk Moderation
02-02-2007, 12:10 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.