PDA

View Full Version : grouping objects after they were created in loop


Hamburger
12-13-2011, 11:30 PM
I have a simple loop in a script, that will create objects inside the loop.

How do I save these objects in a string and group them?

global proc extrudeUp(){

// source extrudeUp.mel; extrudeUp

string $new[];
string $selected[] = `ls -sl`;
string $groupname = "extruded_grp";

if(size($selected)!=0) {

string $result = `promptDialog
-title "Extrude Curve"
-message ("Enter height for extrude length")
-button "Extrude"
-button "Cancel"
-defaultButton "Extrude"
-cancelButton "Cancel"
-dismissString "Cancel"`;

if ($result == "Extrude"){

$text = `promptDialog -q -t`;

for($object in $selected)
{
extrude -ch true -rn false -po 1 -et 0 -upn 0 -d 0 1 0 -length $text -rotation 0 -scale 1 -dl 3 $object;
rename `ls -sl` extrudeUp_temp;
$new = `ls -sl`;
select -r $new;
ConvertSelectionToEdges;
polySoftEdge -a 0 -ch 0 $new;
ConvertSelectionToVertices;
polyMergeVertex -d 0.01 -am 1 -ch 0;
//nathangulate 1;
select -r $new;
delete -ch;
//basePivot;
//resetPivot;
}
// GROUP SHOULD HAPPEN HERE BUT NOT SURE HOW TO DO IT!
changeSelectMode -object;
}
}

else

{
print "// Warning: Nothing selected! \n";
}
}

If I group where that commented line is (group -n $groupname $new; )

Understandably the script will just add in the last looped object.

Mondo
12-14-2011, 12:32 AM
Here you go. A simple counter will do the trick. You'll probably want to give your group a unique name.


global proc extrudeUp(){

// source extrudeUp.mel; extrudeUp

string $new[];
string $selected[] = `ls -sl`;
string $groupname = "extruded_grp";
string $temp[];
string $groupNodes[];


if(size($selected)!=0){
string $result = `promptDialog
-title "Extrude Curve"
-message ("Enter height for extrude length")
-button "Extrude"
-button "Cancel"
-defaultButton "Extrude"
-cancelButton "Cancel"
-dismissString "Cancel"`;

if ($result == "Extrude"){
$text = `promptDialog -q -t`;

for($i=0;$i<size($selected);$i++)
{
$temp = `extrude -ch true -rn false -po 1 -et 0 -upn 0 -d 0 1 0 -length $text -rotation 0 -scale 1 -dl 3 $selected[$i]`;
$temp[0] = `rename $temp[0] extrudeUp_temp`;
polySoftEdge -a 0 $temp[0];
polyMergeVertex -d 0.01 -am 1 $temp[0];
$groupNodes[$i] = $temp[0];
}
// GROUP SHOULD HAPPEN HERE BUT NOT SURE HOW TO DO IT!
group $groupNodes;
changeSelectMode -object;
}else{
print "// Warning: Nothing selected! \n";
}
}

}

Hamburger
12-14-2011, 12:43 AM
Ah cheers, thanks for your help. Makes sense now.

mlefevre
12-14-2011, 12:45 AM
Mondos got it. But I may aswell post it up :)

global proc extrudeUp()
{
string $selected[] = `ls -sl`;

if(size($selected)!=0)
{
//create group if it doesn't already exist. Save the name of it to reference later.
string $surfaceGroup = (`objExists "surface_grp"`) ? "surface_grp" : `group -em -name "surface_grp"`;

string $result = `promptDialog
-title "Extrude Curve"
-message ("Enter height for extrude length")
-button "Extrude"
-button "Cancel"
-defaultButton "Extrude"
-cancelButton "Cancel"
-dismissString "Cancel"`;

if ($result == "Extrude")
{
$text = `promptDialog -q -t`;

for($object in $selected)
{
//pass in -name flag, to name object at creation (maya will increment if name already exists.
//store resulting object in $surface to refer to it for future commands
string $surface[] = `extrude -ch true -rn false -po 1 -et 0 -upn 0 -d 0 1 0 -length $text -rotation 0 -scale 1 -dl 3 -name "extrudeUp_temp" $object`;
polySoftEdge -a 0 -ch 0 $surface[0];
polyMergeVertex -d 0.01 -am 1 -ch 0 $surface[0];
delete -ch $surface[0];
//parent new surface to $surfaceGroup, which we stored earlier.
parent $surface[0] $surfaceGroup;
}
}
else
{
warning("Nothing selected!\n");
}
}
}

Hamburger
12-14-2011, 12:46 AM
Thanks matt. :)

CGTalk Moderation
12-14-2011, 12:46 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.