// =========================================================================== // 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[] stringArrayAddOrRemoveItem( string $originalArray[], int $itemPosition, int $addOrRemove, string $stringToAdd ){ // // Description: // This proc delets an item from a stringArray. // // Arguments: // string $originalArray[]: the string array to modify // int $itemPosition: the current position in the array of the item to remove // int $addOrRemove: 1=add, 0=remove indexed item // string $stringToAdd: if adding, this is the string to add // // Return: // the modified string array string $result[]; int $numItems = `size $originalArray`; //make sure we can delete the item if ($addOrRemove == 1 && $itemPosition > ($numItems - 1) ){ error (uiRes("m_stringArrayAddOrRemoveItem.kIndexedPositionDoesNotExistInTheArray")); return $result; } int $i;//counter for result array int $j;//counter for original array for ($i=0,$j=0;$j<$numItems;$i++,$j++){ if ($i == $itemPosition){ //do nothing but decrement $i so this position is filled next time if ($addOrRemove == 0){ print "\n"; print (uiRes("m_stringArrayAddOrRemoveItem.kDeleting")); print $originalArray[$j]; //increment $j to skip the current item $j++; if ($j < $numItems) { $result[$i] = $originalArray[$j]; } } else { //decrement $j to add this item next time around $j--; $result[$i] = $stringToAdd; } //$result[$i] = $originalArray[$i]; } else { $result[$i] = $originalArray[$j]; } } return $result; }