PDA

View Full Version : Breaking connections in a script


tymznd
04-03-2003, 08:07 PM
I have scripted the creation of a motionpath. And now I wish to connectAttr into the "u" value.... so I first need to break the connection that is there by default. When I echo all commands and do it by hand I get:
channelBoxCommand -break;
CBdeleteConnection "L_mouth_corner_path_null_moPath.u";

and if I type this into the command line:
CBdeleteConnection motionPath1.u;

it works......

...but when I run my script with the same command:
nullPath;
// Error: Cannot find procedure "CBdeleteConnection". //

I assum that the "CB" is for channel box.... is the error becuase the script isn't really clicking on the channel box??

tymznd
04-03-2003, 08:53 PM
Ok - it does work if I first do it by hand.... so I assume that Maya doesn't have that command loading into memory upon initial startup, but if you do it by hand then the proc CBdeleteConnection gets loaded in... and then scripts can use it.... this woln't work for me.

If I run the following it works but leaves behind unwanted nodes:
disconnectAttr motionPath1_uValue.output motionPath1.uValue;
// Result: Disconnected motionPath1_uValue.output from motionPath1.uValue //

alexx
04-03-2003, 09:03 PM
dont ask me what CBdeleteConnection exactely does.. but the disconnectAttr command is the way to go anyway

cheers

alexx

bigfatMELon
04-04-2003, 08:15 AM
CBdeleteConnection is a Maya function that gets sourced and when you first break a connection in the channel box. It's a higher level wrapper for handling channel box breakages used by the channel box option menu. So, if you use this same wrapper without first having used the break function of the channel box by hand, then it does't yet exist and you get your error.

While this is what gets echoed to the script editor when you break a connection, the command you really want is disconnectAttr as alexx pointed out.

-jl

tymznd
04-04-2003, 08:35 AM
Thanks to both of you...

Here is what I ended up using:
delete $u_val_node;

This was the only way that I could get rid of all the unwanted nodes in one swoop.

:rolleyes:

mark_wilkins
04-04-2003, 06:27 PM
This is a big reason that you need to be very careful when using "Echo All Commands" to see what MEL is being generated by the UI.

People teach this approach all the time but they rarely bother to mention that it requires really looking at the commands that get spit back to see whether they make any sense.

Usually I'll take whatever I get back from "Echo All Commands" in the script editor and use the whatIs command to find out where it's defined. if it's a built in command I'm good to go -- more often it's a procedure that's in a MEL file that shipped with Maya, and reading the procedure will give me a better idea of how to proceed than just trying to use the command unmodified.

-- Mark

CaptainSam
04-07-2003, 06:00 PM
The CBdeleteConnection proc doesnt get sourced until the user right clicks the channelBox (which is why you always get that little pause before the menu pops uip the first time you right click). Like Mark said, the whatIs command will tell you what script the command is from. Then all you need to do is to source that script to make sure that the procedure exists when you run your script. In this case source generateChannelMenu

mark_wilkins
04-07-2003, 06:05 PM
Usually, though, you're better off finding the underlying MEL command that that function is calling, like deleteAttr.

-- Mark

DangerAhead
08-05-2005, 11:11 PM
MarkI use the CBdeleteConnection because It's an extra step to find the other part of the connection in the disconnectAttr command.

I use "Break Connections" a lot. and I only know I don't want that particular attr to have a connection (sometimes I can't remember what it's connected to).

I made this. I basically took the content of the CBdeleteConnection proc and put it in this one. no change at all.

global proc gmDeleteConnection( string $destName )
//
// If the specified name is the destination of a connection,
// then delete that connection.
//
{
if ( `connectionInfo -isDestination $destName` ){
string $destination = `connectionInfo -getExactDestination $destName`;
// When deleting a src connection from a character, you must remove
// the item from the character set or the character will no longer
// work consistently: bug 127212
//
string $srcConn[] = `listConnections -s 1 -d 0 -type character $destination`;
if (size($srcConn)) {
string $warnMsg = ("Removed \'"+$destination+"\' from character \'"+$srcConn[0]+"\'.");
warning($warnMsg);
character -e -rm $srcConn[0] $destination;
}

// delete -icn doesn't work if destination attr is readOnly
// so use disconnectAttr in this case
//
string $sArr[1] = `ls -ro $destination`;
if (size($sArr)) {
string $src = `connectionInfo -sourceFromDestination $destination`;
disconnectAttr $src $destination;
} else {
delete -icn $destination;
}
}
}

CGTalk Moderation
08-05-2005, 11:11 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.