PDA

View Full Version : polySeperate help . . . argh


AtrusDni
01-05-2007, 02:37 AM
Ok so what i am trying to do is this, image that you have 2 spheres, offset from eachother so they aren't intersecting, and you combine them, delete history etc. You are left with "technically" 1 object, but its composed of 2. Ok this is what we will call "object1".

Next you just have a normal sphere. "object2".

What I am trying to do is break apart all objects that arent connected, and return the names in an array for both objects.

I already have both objects names stored in strings like so:

string $obj1 = "object1";
string $obj2 = "object2";

what im trying to do is get 2 arrays to gather the contents after seperation like so:
string $multiObjLst1[] = `polySeperate $obj1`;
string $multiObjLst2[] = `polySeperate $obj2`;

then combine the arrays to have a master list:
string $allObjs[] = stringArrayCatenate($multiObjLst1,$multiObjLst2);


From what I can tell, the first one works fine because it is the two combined sphere objects, but the second one just errors out saying that its just one object. I know its one object, but is there anyway to run the polySeperate command and even if its just 1 object store that into the array and catenate them? Am I going about this all wrong? Any info would be mucho appreciated. Thanks.

P.S. - with this example obviously we know which should be seperated and which shouldnt, but imagine a scene thats hundreds of objects and maya needs to figure out if its really one object or if it can break it apart, if that makes sense . . .

grantimus
01-05-2007, 09:31 AM
The polySeparate command will break apart an object into as many parts as it can on its own. If you have two combined spheres and run polySeparate, it should return an array of two objects. If you have a thousand combined spheres polySeparate should return an array of a thousand objects. There is no need to try and write some kind of recursive function. But, maybe I'm misunderstanding you're problem.

Oh and btw, if you want to use a command that will error out in some instances (i.e. running polySeparate on a mesh with one object) but not in others, the "catch" command might be the answere to your problems. Look at the help docs for more info.

AtrusDni
01-05-2007, 05:07 PM
Ok well my problem is I have done a lot of boolean operations on objects and sometimes when you do a boolean, you are left with an object that really should be 2 objects, so if you cut 2 lines through a torus, you are left with 2 "C" shapes, and a middle piece that should really be 2 objects, so the total object count should be 4 not 3. What I want to do is run a script that will seperate the objects that need to be seperated, gather the names of all the new objects and rename them . . .

I also tried using the catch command and it still errors out. No luck there :-(

grantimus
01-06-2007, 06:19 AM
Ok I think I have a better idea of what you're after. A setup like this might help you:


string $obj1 = "object1";
string $obj2 = "object2";
string $multiObjLst1[];
string $multiObjLst2[];
string $cmd1 = "$multiObjLst1 = `polySeperate $obj1`";
string $cmd2 = "$multiObjLst2 = `polySeperate $obj2`";

$errorCheck1 = catch(eval($cmd1));
$errorCheck2 = catch(eval($cmd2));

if($errorCheck1){
print($obj1 + " is only one peice\n");
$multiObjLst1 = {$obj1};
}

if($errorCheck2){
print($obj2 + " is only one peice\n");
$multiObjLst2 = {$obj2};
}

string $allObjs[] = stringArrayCatenate($multiObjLst1,$multiObjLst2);
for($i=0;$i<size($allObjs);$i++){
rename $allObjs[$i] ("renamedObj" + $i);
}


The script will still report errors if it can't separate the objects, there is no way around this (that I know of anyway). But, it will still run in spite of the errors.

grantimus
01-06-2007, 07:00 AM
I think I might have found an easier way. `polyEvaluate -shell` will return the number of shells in an object. If that number is greater than 1, you know that object can be separated.

AtrusDni
01-07-2007, 04:24 AM
ahhhh !!! I like the sounds of that last one grantimus, lemme check it out real quick, but I think that is exactly what I was looking for.

AtrusDni
01-07-2007, 04:28 AM
YAY! it worked perfectly grantimus, thank you for your help! Hurray for no more errors.

CGTalk Moderation
01-07-2007, 04:28 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.