// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== global proc string[] stringArrayMoveItem( string $originalArray[], int $itemPosition, int $direction ){ // // Description: // This proc moves an item up or down one position in a stringArray. // // Arguments: // string $originalArray[] the string array to modify // int $itemPosition the current position in the arrayof the item to move // int $direction 1=move down, -1=move up // // Return: // the modified string array string $result[]; int $newPosition; //make sure we can move the item if ($newPosition > 1 || $newPosition < `size $originalArray`){ $newPosition = $itemPosition + $direction; } else { error (uiRes("m_stringArrayMoveItem.kItemIsAlreadyAtStartOrEndOfTheArray")); return $result; } int $i; int $numItems = `size $originalArray`; //move up if ($direction == -1){ for ($i=0;$i<$numItems;$i++){//need to loop 1 time less than size of array if ($i < $newPosition){ $result[$i] = $originalArray[$i]; } else if ($i == $newPosition){ //if ($newPosition == $i){ $result[$i] = $originalArray[$itemPosition]; $result[$i+1] = $originalArray[$i]; $i++; $newPosition--; } else { $result[$i] = $originalArray[$i]; } } } else //move down { for ($i=0;$i<$numItems;$i++){ if ($i < $itemPosition){ $result[$i] = $originalArray[$i]; } else if ($i == $itemPosition){ $result[$i] = $originalArray[$newPosition]; $result[$i+1] = $originalArray[$itemPosition]; $i++; } else { $result[$i] = $originalArray[$i]; } } } return $result; }