Jan 2007
1 / 3
Jan 2007
Jan 2007

Hey guys-

I am looking to create a script that deletes duplicates based on exactWorldBoundingBox. So Far so good, I am sure it sould be much shorter, but here goes... I need to redefine the variable: $objs, each time it loops, but I get an error the the first object no longer exists because it deleted it. I am unsure of where to redefine the variable in the loop. Any help would be great.

CODE
string $objs[];
{

$objsTemp = ls -type mesh;
$objs = $objsTemp;
$objsSize = size ($objs);

for ($u = 0; $u < $objsSize; $u++){
    select -r $objs;
    select -d $objs[$u];
    $otherObjs = `ls -sl -fl`;
    $otherObjsSize = size ($otherObjs);

select -r $objs[$u];

float $bb[] = exactWorldBoundingBox;

float $rpX = (( $bb[ 3 ] - $bb[ 0 ] ) / 2 + $bb[ 0 ] );
float $rpY = (( $bb[ 4 ] - $bb[ 1 ] ) / 2 + $bb[ 1 ] );
float $rpZ = (( $bb[ 5 ] - $bb[ 2 ] ) / 2 + $bb[ 2 ] );

float $rp[3];
$rp[0] = $rpX;
$rp[1] = $rpY;
$rp[2] = $rpZ;
    for ($y = 0; $y < $otherObjsSize; $y++){
        select -r $otherObjs[$y];        
        float $bb[] = exactWorldBoundingBox;

    float $rpX = (( $bb[ 3 ] - $bb[ 0 ] ) / 2 + $bb[ 0 ] );
    float $rpY = (( $bb[ 4 ] - $bb[ 1 ] ) / 2 + $bb[ 1 ] );
    float $rpZ = (( $bb[ 5 ] - $bb[ 2 ] ) / 2 + $bb[ 2 ] );

    float $rp2[3];
    $rp2[0] = $rpX;
    $rp2[1] = $rpY;
    $rp2[2] = $rpZ;

        if ( $rp[0] == $rp2[0]){
                if ( $rp[1] == $rp2[1]){
                        if ( $rp[2] == $rp2[2]){
                                delete $otherObjs[$y];
                        }
                }
        }

}

}
$objsTemp =ls -type mesh;
}

Hope that is kinda clear

I have done this before, but can't seem to figure it out. I know this is really basic, but hey...

Thanks

Sheriif

  • created

    Jan '07
  • last reply

    Jan '07
  • 2

    replies

  • 3.6k

    views

  • 1

    user

Instead of deleting, you can add your objects to a "delete list" and do the deletion in a second step outside the loop...

define a new array

string $toDelete[];
int $toDelIndex = 0;

then replace your line
delete $otherObjs[$y];

with
$toDelete[$toDelIndex++] = $otherObjs[$y];

and after the loop:
delete $toDelete;

um well...

I get what your are doing, but the problem is that this deletes any object that occupies the same space.. regaurdless of which iteration of the loop it is on... so this will delete all the objects accept for the last one... Any other Ideas?

Thanks

Sheriff