PDA

View Full Version : Help with deleting


xcomb
10-27-2006, 11:06 AM
Hi all!

Well i created simple UI that pretty much selects objects in a scene and displays their attributes, i do that for practicing.
So the thing is i was able to select and set keyframes on multiple objects, and list all their attributes into another textScrollList, but when comes to deleting all keyframes i am only able to delete on one selected. This has to do with loops, whcih i can't get the sence.
Take a look all the way in the bottom, i am putting whole script.
Sorry for the mess, i believe there should be two loops to loop first for selected objects, let's say 3 times, and loop to select their attributes, then to use the deletion function.

if(`window -exists mainWindow`)
deleteUI mainWindow;
//windowPref -r mainWindow;
window -title "Main" -width 300 -height 400 mainWindow;
columnLayout -adj 1 mainCol;
textScrollList -width 285 -height 350 -ams true mainText;
popupMenu Menu;
menuItem -l "List Attributes" -c "listAttributes()";
button -l "Refresh" -c "refreshBtn()" mainBtn;
showWindow mainWindow;

global proc refreshBtn()
{
textScrollList -e -ra mainText;
string $selected[] = `ls -l -sl`;
for($i in $selected){
textScrollList -e -append $i mainText;
}
}

global proc listAttributes()
{
string $listAttr[] = `textScrollList -q -si mainText`;
int $size = size($listAttr);
for($i = 0; $i <= size($listAttr); $i++){
string $listAttributes[] = `listAttr -k $listAttr`;
int $sizeAttr = size($listAttributes);
if (`window -exists attrWindow`)
deleteUI attrWindow;
window -title "Attributes" -width 200 -height 300 attrWindow;
columnLayout -adj 1 attrCol;
textScrollList -width 200 -height 250 -ams true attrText;
popupMenu attrMenu;
menuItem -l "Key" -c "keyThem()";
menuItem -l "Delete Key" -c "deleteThem()";

for($i = 0; $i <= $sizeAttr; $i++){
textScrollList -e -append $listAttributes[$i] attrText;
}
string $selectedAttrs[] = `textScrollList -q -si attrText`;
for($j = 0; $j <= size($selectedAttrs); $j++){
setKeyframe -at $selectedAttrs[$j];
}
showWindow attrWindow;
}
}
global proc keyThem()
{
string $selectedAttrs[] = `textScrollList -q -si attrText`;
for($j = 0; $j <= size($selectedAttrs); $j++){
setKeyframe -at $selectedAttrs[$j];
}
}

//RIGHT HERE :(

global proc deleteThem(){
string $listAttr[] = `textScrollList -q -si mainText`;
string $selectedAttrs[] = `textScrollList -q -si attrText`;
int $size = size($listAttr);
int $sizeAttr = size($selectedAttrs);
for($j = 0; $j <= $sizeAttr; $j++){
for($k = 0; $k <= size($selectedAttrs); $k++){
CBdeleteConnection ($listAttr[$j] + "." + $selectedAttrs[$k]);
}
}
}

xcomb
10-27-2006, 11:21 AM
Hmm weired, i got working only when i specified the number or attributes in one node which is 9, so it deleted on all selected objects.
Maybe you can at least explain me, so i don't have to manually enter the correct amount of attributes for all objects.
global proc deleteThem(){
string $listAttr[] = `textScrollList -q -si mainText`;
string $selectedAttrs[] = `textScrollList -q -si attrText`;
int $size = size($listAttr);
int $sizeAttr = size($selectedAttrs);
for($j = 0; $j <= $sizeAttr; $j++){
for($k = 0; $k <= 9; $k++){
CBdeleteConnection ($listAttr[$j] + "." + $selectedAttrs[$k]);
}
}
}

meljunky
10-30-2006, 07:17 PM
On the first for loop, you are referenceing $sizeAttr as the conditional part of the loop which is from the array $selectedAttr. The frist loop is refering to the objects and should use the array $listAttr when refering to the conditional part... it needs to be the variable $size. The second loop is where you are cycling through the attributes, so the 9 can be $sizeAttr
global proc deleteThem(){
string $listAttr[] = `textScrollList -q -si mainText`;
string $selectedAttrs[] = `textScrollList -q -si attrText`;
int $size = size($listAttr);
int $sizeAttr = size($selectedAttrs);
for($j = 0; $j <= $size; $j++){
for($k = 0; $k <= $sizeAttr; $k++){
CBdeleteConnection ($listAttr[$j] + "." + $selectedAttrs[$k]);
}
}
}

I notice that you repeat attributes when multiple objects are selected... might want to remove dulplicates. Also, when dealing with user defined attributes... it will be unable to delete keys when they don't exists... catchQuiet the CBdeleteConnection should get around that.

-Brian
www.meljunky.com (http://www.meljunky.com/)

xcomb
10-30-2006, 08:41 PM
Thanks for your suggestion!

CGTalk Moderation
10-30-2006, 08:41 PM
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.