PDA

View Full Version : Reset All problem


Rupesh1122
07-28-2008, 06:46 AM
Hi All,
I have a mel that resets translate, rotate, scale, Reset All values through button click in window.
If any attribute is locked, then click on Reset All button. It works fine but it displays:
// Error: A child attribute of 'pSphere1.rotate' is locked or connected and cannot be modified.

I dont want to recieve any error while click on Reset All button (object's any attribute in lock)
Please help.


global int $def=1;

if (`window -ex Win`)

deleteUI Win;



window -s off -t "RESET" Win;

frameLayout -l "" -bs "in";

columnLayout;

rowLayout -numberOfColumns 3;

button -w 70 -label " Translate" -command "resetObj_proc1(`ls -sl`,$def)";

button -w 70 -label " Rotate" -command "resetObj_proc2(`ls -sl`,$def)";

button -w 70 -label " Scale" -command "resetObj_proc3(`ls -sl`,$def)";

setParent..;

text -fn boldLabelFont "\n";

rowLayout -numberOfColumns 3;

button -vis off;

button -w 70 -label " RESET ALL" -command "resetObj_proc1(`ls -sl`,$def);resetObj_proc2(`ls -sl`,$def);resetObj_proc3(`ls -sl`,$def)";

button -vis off;

setParent..;

global proc resetObj_proc1(string $ctrl_reset[],int $set)

{

for($obj in $ctrl_reset)

{

if ($set == 1) setAttr ($obj + ".translate") 0 0 0;

}

}

global proc resetObj_proc2(string $ctrl_reset[],int $set)

{

for($obj in $ctrl_reset)

{

if ($set == 1) setAttr ($obj + ".rotate") 0 0 0;

}

}

global proc resetObj_proc3(string $ctrl_reset[],int $set)

{

for($obj in $ctrl_reset)

{

if ($set == 1) setAttr ($obj + ".scale") 1 1 1;

}

}



window -e -w 280 -h 120 Win ;

showWindow Win;



Thanks in Advance

ashishdantu
07-28-2008, 09:15 AM
hi rupesh,


global proc resetObj_proc1(string $ctrl_reset[],int $set)
{
for($obj in $ctrl_reset)
{
if (size(`listConnections ($obj + ".translateX")`) || size(`listConnections ($obj + ".translateY")`) || size(`listConnections ($obj + ".translateZ")`))
{
warning ($obj+" translate channels are locked/connected, so ignored.");
}
else
{
if ($set == 1)
setAttr ($obj + ".translate") 0 0 0;
}
}

}
resetObj_proc1(`ls -sl`,1);


here i just added the checking to see if a particular channel is locked (or rather having incoming connections) using size(`listConnections ($obj + ".translateX"))

if no incoming connections are found, the channels get set to 0...

hope this helps...

ashishdantu
07-28-2008, 09:30 AM
hi rupesh,

just added ...another flag so you can use the same function for translate, rotate and scale..


global proc resetObj_proc1(string $ctrl_reset[],string $trs,int $set)
{
for($obj in $ctrl_reset)
{
if (size(`listConnections ($obj + "."+$trs+"X")`) || size(`listConnections ($obj + "."+$trs+"Y")`) || size(`listConnections ($obj + "."+$trs+"Z")`))
{
warning ($obj+" "+$trs+" channels are locked/connected, so ignored.");
}
else
{
if ($set == 1 && $trs != "scale")
setAttr ($obj + "."+$trs+"") 0 0 0;
else if ($set == 1 && $trs == "scale")
setAttr ($obj + "."+$trs+"") 1 1 1;

}
}

}


so to use it for translate > resetObj_proc1(`ls -sl`,"translate",1);
so to use it for rotate> resetObj_proc1(`ls -sl`,"rotate",1);
so to use it for scale > resetObj_proc1(`ls -sl`,"scale",1);

hope u got the idea and shud be able to reduce ur code... :)

Rupesh1122
07-28-2008, 10:43 AM
Hi Ashish,
Thanks for your reply.

I edit the script with 'list connections'. But it's not working.

NaughtyNathan
07-28-2008, 11:10 AM
else
{
int $sc = ($trs=="scale");
setAttr ($obj + "."+$trs+"") $sc $sc $sc;
}

is reduced even more and more efficient! :).

also, the $def/$set flag is totally redundant. I'd get rid of it.

:nathaN

Rupesh1122
07-28-2008, 11:57 AM
ya Nathan, It reduces the code length.
But still Reset ALL button displays error
How to fix this problem?

NaughtyNathan
07-28-2008, 02:08 PM
have you edited the "reset all" button command to incorporate ashishdantu's new parameter ($trs)..? I thought not.. ;)

anyway, here's the edited code working, and optimized somewhat. It should all work as I have tested it. I've got rid of some stuff that was pointless (try to avoid global vars, and creating UI elements that are unnecessary...)


global proc resetObj_proc(string $ctrl_reset[],string $trs)
{
for($obj in $ctrl_reset)
{
if (size(`listConnections ($obj + "."+$trs+"X")`) || size(`listConnections ($obj + "."+$trs+"Y")`) || size(`listConnections ($obj + "."+$trs+"Z")`))
warning ($obj+" "+$trs+" channels are locked/connected, so ignored.");
else
{
int $isScale = ($trs=="scale");
setAttr ($obj+"."+$trs) $isScale $isScale $isScale;
}
}
}
{
if (`window -ex Win`) deleteUI Win;
window -s off -t "RESET" Win;
frameLayout -l "" -bs "in";
columnLayout -adj 1 -rs 8 ;
rowLayout -numberOfColumns 3 -cl3 center center center;
button -w 70 -label "Translate" -command "resetObj_proc `ls -sl` translate";
button -w 70 -label "Rotate" -command "resetObj_proc `ls -sl` rotate";
button -w 70 -label "Scale" -command "resetObj_proc `ls -sl` scale";
setParent..;
button -label "RESET ALL" -command "resetObj_proc `ls -sl` translate;resetObj_proc `ls -sl` rotate;resetObj_proc `ls -sl` scale";
setParent..;
window -e -w 280 -h 120 Win ;
showWindow Win;
}

ashishdantu
07-29-2008, 02:13 AM
hi Nathan,


int $isScale = ($trs=="scale");
setAttr ($obj+"."+$trs) $isScale $isScale $isScale;


nice tip :applause: !

ashishdantu
07-29-2008, 08:44 AM
global proc resetObj_proc(string $ctrl_reset[],string $trs)
{
for($obj in $ctrl_reset)
{
if (size(`listConnections ($obj + "."+$trs+"X")`) || size(`listConnections ($obj + "."+$trs+"Y")`) || size(`listConnections ($obj + "."+$trs+"Z")`) || `getAttr -l ($obj + "."+$trs+"X")` || `getAttr -l ($obj + "."+$trs+"Y")` || `getAttr -l ($obj + "."+$trs+"Z")`)
{
warning ($obj+" "+$trs+" channels are locked/connected, so ignored.");
}
else
{
int $isScale = ($trs=="scale");
setAttr ($obj+"."+$trs) $isScale $isScale $isScale;
}
}
}

{
if (`window -ex Win`) deleteUI Win;
window -s off -t "RESET" Win;
frameLayout -l "" -bs "in";
columnLayout -adj 1 -rs 8 ;
rowLayout -numberOfColumns 3 -cl3 center center center;
button -w 70 -label "Translate" -command "resetObj_proc `ls -sl` translate";
button -w 70 -label "Rotate" -command "resetObj_proc `ls -sl` rotate";
button -w 70 -label "Scale" -command "resetObj_proc `ls -sl` scale";
setParent..;
button -label "RESET ALL" -command "resetObj_proc `ls -sl` translate;resetObj_proc `ls -sl` rotate;resetObj_proc `ls -sl` scale";
setParent..;
window -e -w 280 -h 120 Win ;
showWindow Win;
}


added the check for Locked channel using the `getAttr -lock (attrib)`

`getAttr -l ($obj + "."+$trs+"X")` || `getAttr -l ($obj + "."+$trs+"Y")` || `getAttr -l ($obj + "."+$trs+"Z")`

hope this solves ur error !

Rupesh1122
07-29-2008, 09:07 AM
Wow, It's working.
Thanks a lot Ashish.:bounce:

CGTalk Moderation
07-29-2008, 09:07 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.