Break Connections with translation and rotation

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 04 April 2013   #1
Break Connections with translation and rotation

Hey Everyone,

I've been searching this forum and have found a few posts that I thought might answer my question but I am still having problems.

I'm just trying to take a locator and break all connections with translation (x,y,z) and rotation (x,y,z) attributes (like what you would do manually in the channel box).

I have come across CBdeleteConnections but I am trying to stick with an all python approach.
I've also run into disconnectAttr but it seemed to me that that command is more about separating the relationship between objects that shared a common attribute rather than separating a single object from a single attribute (like translate X, for example).

I assume there is a really simple way to do this, I just haven't found it yet. (Or I'm doing disconnectAttr wrong).

Thanks,

Brian
 
Old 04 April 2013   #2
not really , i believe the disconnect attribute is the way to go ,

just get the source connecttion for each attribute and then call the disconnectAttr

example with pseudo code

#query the connection
conn = cmds.listConnections(myLoc + '.tx' , source = 1 , p = 1)[0]

#now break
cmds.disconnectAttr(conn , myLoc +'.tx' )

that should do , I have no maya open right now but that s usually my workflow
__________________
My website/blog , with a lot of tips&tricks about maya API,python,and pyqt , and tutorials
www.marcogiordanotd.com
llinkedin
 
Old 04 April 2013   #3
Great, that works really well.

Although now my problem is that those attributes aren't always connected, so if I run the script to disconnect translateX, and there is no keyed translateX attribute, I get an error.

Can I check first to see if it exists and then break it?

I tried something like:

if conn is not none
cmds.disconnectAttr(conn0 , locNm + ".tx" )

But that didn't work.

Any help is appreciated.

Thanks again,
Brian
 
Old 04 April 2013   #4
Originally Posted by brianharms: Great, that works really well.

Although now my problem is that those attributes aren't always connected, so if I run the script to disconnect translateX, and there is no keyed translateX attribute, I get an error.

Can I check first to see if it exists and then break it?

I tried something like:

if conn is not none
cmds.disconnectAttr(conn0 , locNm + ".tx" )

But that didn't work.

Any help is appreciated.

Thanks again,
Brian



this worked no problem for me :
from maya import cmds conn = cmds.listConnections("locator1.tx" ,s = 1 , p = 1) if conn : cmds.disconnectAttr(conn[0] , "locator1.tx") else : print "not connected"
__________________
My website/blog , with a lot of tips&tricks about maya API,python,and pyqt , and tutorials
www.marcogiordanotd.com
llinkedin
 
Old 05 May 2013   #5
Originally Posted by brianharms: I tried something like:

if conn is not none
cmds.disconnectAttr(conn0 , locNm + ".tx" )

But that didn't work.

Any help is appreciated.



Personally I'd always want to store the results and then run the disconnect if the result was not empty or run some sort of other kind or error checking. For example the connection could be locked or you might only wish to break connections to animCurves instead of other sources.
__________________
blah blah blah

Last edited by gmask : 05 May 2013 at 04:12 PM.
 
Old 05 May 2013   #6
Just got around to trying this. Worked perfectly - but instead of writing out each specific attribute, now I'm trying to loop through all attributes automatically and disconnect the ones that are connected within the type "transform."

import maya.cmds as mc

locNm = "myObject"

conn = (mc.listConnections(locNm, t ="transform", s = 1, p = 1))

for i in range(0,len(conn)):

if conn[i]:
mc.disconnectAttr(conn[i] , locNm)
else :
print "not connected"

But I get an error:

# Error: line 1: RuntimeError: file <maya console> line 11: The destination attribute cannot be found. #

I'm thinking it's because in:

mc.disconnectAttr(conn[i] , locNm)

locNm needs actual attributes listed, not just the object name - but I'm not sure how to list all transform attributes of an object (locNm.transform?)

Last edited by brianharms : 05 May 2013 at 10:38 AM.
 
Old 05 May 2013   #7
This works perfectly and is ultimately what I'm trying to achieve:

import maya.cmds as mc

locNm = myObject

conn1 = mc.listConnections(locNm + ".tx",s = 1 , p = 1)
conn2 = mc.listConnections(locNm + ".ty",s = 1 , p = 1)
conn3 = mc.listConnections(locNm + ".tz",s = 1 , p = 1)
conn4 = mc.listConnections(locNm + ".rx",s = 1 , p = 1)
conn5 = mc.listConnections(locNm + ".ry",s = 1 , p = 1)
conn6 = mc.listConnections(locNm + ".rz",s = 1 , p = 1)

if conn1 :
mc.disconnectAttr(conn1[0] , locNm + ".tx")
if conn2 :
mc.disconnectAttr(conn2[0] , locNm + ".ty")
if conn3 :
mc.disconnectAttr(conn3[0] , locNm + ".tz")
if conn4 :
mc.disconnectAttr(conn4[0] , locNm + ".rx")
if conn5 :
mc.disconnectAttr(conn5[0] , locNm + ".ry")
if conn6 :
mc.disconnectAttr(conn6[0] , locNm + ".rz")


But in the future there may be more keyed attributes, so an automated solution would be best.
 
Old 05 May 2013   #8
why dont you put everything in a loop?

make a list of the attributes and loop them

pseudo code

for a in [tx ,ty,tz] :
conn = mc.listConnections(locNm + "." + a ,s = 1 , p = 1)
if conn :
mc.disconnectAttr(conn[0] , locNm + "." + a)
__________________
My website/blog , with a lot of tips&tricks about maya API,python,and pyqt , and tutorials
www.marcogiordanotd.com
llinkedin
 
Old 05 May 2013   #9
ps indentation is gone =_=
__________________
My website/blog , with a lot of tips&tricks about maya API,python,and pyqt , and tutorials
www.marcogiordanotd.com
llinkedin
 
Old 05 May 2013   #10
That's much cleaner. Thanks for your help giordi.
 
Old 05 May 2013   #11
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 03:04 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.