# Break Connections

**URL:** https://forum.highend3d.com/t/break-connections/975
**Category:** Maya
**Tags:** mel
**Created:** [July 10, 2009, 1:54pm UTC](https://forum.highend3d.com/t/break-connections/975 "2009-07-10T13:54:14Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ramesh03](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@ramesh03](https://forum.highend3d.com/u/ramesh03)
#### Post date: [July 10, 2009, 1:54pm UTC](https://forum.highend3d.com/t/break-connections/975/1 "2009-07-10T13:54:14Z")

</div>

Hi,  
i want to break texture and shader connections through MEL,  
but the problem with layeredShaders and normal Shaders(blinn,lambert etc...)  
How to make the condition here to break both the shaders at a time.  
This is my script now it breaks LayeredShaders,but problem with normal shader nodes.

global proc breakTexConnections()  
{  
 string $selList[] = `ls -mat`;  
 string $selTex[] = `ls -tex`;  
 string $lShader[] = `ls -typ "layeredShader"`;  
 for( $i=0; $i\<size( $selList ); $i++ )  
 {  
 catch(`connectionInfo -id ($lShader[$i] +".inputs[0]" + ".color" )`);  
 string $breakInfo = `connectionInfo -sourceFromDestination ( $lShader[$i] +".inputs[0]" + ".color" )`;  
 catch ( `disconnectAttr $breakInfo ( $lShader[$i] +".inputs[0]" + ".color" )` );  
 setAttr ($lShader[$i] +".inputs[0]" + ".color") -type double3 1 1 1 ;   
 }  
 if( `connectionInfo -id ( $selList[$i] + ".color" )` )  
 {  
 string $breakInfo = `connectionInfo -sourceFromDestination ( $selList[$i] + ".color" )`;  
 catch ( `disconnectAttr $breakInfo ( $selList[$i]+".color" )` );  
 setAttr ($selList[$i]+".color") -type double3 1 1 1;  
 setAttr "layeredShader1.inputs[0].color" -type double3 1 1 1 ;   
 }  
}

Thanks.

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [July 10, 2009, 2:41pm UTC](https://forum.highend3d.com/t/break-connections/975/2 "2009-07-10T14:41:54Z")

</div>

You shoudl actually do it differently. you should ask all shading groups in existence then list all their connections and disconnect them.

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [July 10, 2009, 3:02pm UTC](https://forum.highend3d.com/t/break-connections/975/3 "2009-07-10T15:02:33Z")

</div>

Not sure what your exactly after but thsi should do the trick:

CODE  
for ($item in listHistory("-f",0,"-ag",1,`ls -et shadingEngine`)){  
&nbsp;&nbsp;$list=getEverySecond2(`listConnections -c 1 -p 1 -s 0 -d 1 $item`);  
&nbsp;&nbsp;for($i=0;$i\<size($list);$i+=1){  
&nbsp;&nbsp;&nbsp;&nbsp;if (`match "[.]color$" $list[$i+1]`!=""){  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print ("disconnected: "+`connectionInfo -sfd $list[$i+1]`+" "+$list[$i+1]);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;disconnectAttr&nbsp;&nbsp;`connectionInfo -sfd $list[$i+1]` $list[$i+1];  
&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;}

}

---

<div class="post-metadata">

### Author: ![atilla99](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@atilla99](https://forum.highend3d.com/u/atilla99)
#### Post date: [July 10, 2009, 3:14pm UTC](https://forum.highend3d.com/t/break-connections/975/4 "2009-07-10T15:14:29Z")

</div>

CODE  
global proc breakTexConnections()  
{  
&nbsp;&nbsp;&nbsp;&nbsp;string $selTex[] = `ls -tex`;  
&nbsp;&nbsp;&nbsp;&nbsp;for($each in `ls -mat`)  
&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;if(`nodeType $each` == "layeredShader")  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string $LSconns[] = `listConnections -c 1 -s 1 -d 0 $each`;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for($LScon in $LSconns)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string $buffer[];  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tokenize ($LScon, ".", $buffer);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(`gmatch $buffer[1] "inputs*"`)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string $theSource = `connectionInfo -sourceFromDestination $LScon`;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;disconnectAttr $theSource $LScon;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string $theNode = $buffer[0];  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string $theAttr = $buffer[1];  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setAttr ($theNode + "." + $theAttr + ".color") -type double3 1 1 1;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;string $conns[] = `listConnections -p 1 -s 1 -d 0 $each`;  
&nbsp;&nbsp;&nbsp;&nbsp;for ($conn in $conns)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string $buffer02[];  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tokenize($conn, ".", $buffer02);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string $nodeName = $buffer02[0];  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string $nodeType[] = `nodeType -i $nodeName`;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($nodeType[0] == "texture2d" || $nodeType[0] == "texture3d")  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string $theDestination[] = `connectionInfo -destinationFromSource $conn`;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;disconnectAttr $conn $theDestination[0];  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;}  
}

I know little bit long but It works for me. Hope it helps.

---

<div class="post-metadata">

### Author: ![jamie\_3d](https://forum.highend3d.com/user_avatar/forum.highend3d.com/jamie_3d/32/195_2.png) [@jamie\_3d](https://forum.highend3d.com/u/jamie_3d)
#### Post date: [July 10, 2009, 6:34pm UTC](https://forum.highend3d.com/t/break-connections/975/5 "2009-07-10T18:34:54Z")

</div>

CODE  
source channelBoxCommand.mel;  
for($i in `ls -mat`){  
&nbsp;&nbsp;&nbsp;&nbsp;if(`nodeType $i` != "layeredShader"){  
&nbsp;&nbsp;&nbsp;&nbsp;CBdeleteConnection($i+".color");  
&nbsp;&nbsp;&nbsp;&nbsp;CBdeleteConnection($i+".transparency");  
&nbsp;&nbsp;&nbsp;&nbsp;CBdeleteConnection($i+".incandescence");  
&nbsp;&nbsp;&nbsp;&nbsp;if(`nodeType $i` != "particleCloud")  
&nbsp;&nbsp;&nbsp;&nbsp;CBdeleteConnection($i+".ambientColor");  
&nbsp;&nbsp; }  
}

QUOTE  
I know little bit long but It works for me. Hope it helps.

![]()

---

<div class="post-metadata">

### Author: ![ramesh03](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@ramesh03](https://forum.highend3d.com/u/ramesh03)
#### Post date: [July 14, 2009, 10:36am UTC](https://forum.highend3d.com/t/break-connections/975/6 "2009-07-14T10:36:30Z")

</div>

Yah, its working but, the problem with shader to render node shader connections.like blinn.outColor and Phonge.color.There is no connection then i want that material 1 1 1. My file has various connections.and also  
where we can find "channelBoxCommand.mel" ?
