Discussion:
[Maya-Python] Remove reference edits via Python?
Fredrik Averpil
2014-10-30 11:46:09 UTC
Permalink
Hi,

I’m having problems performing this via Python. If using the UI, you would
right click the reference and choose to list the reference edits. Then you
can select each edit and hit “Remove reference edit”.

I’ve successfully been able to list reference edits in various ways with:

cmds.referenceQuery( "soffaRN", editStrings=True )
Result: [u'parent -s -r "|kuddar:pillows1" "|model2670"',
u'parent -s -r "|kuddarRNfosterParent1|pillow_04"
"|model2670|kuddar:pillows1"',
u'setAttr |soffa:model2670.translate -type "double3" -506.529608
65.636552 493.906544',
u'setAttr |soffa:model2670.rotate -type "double3" 212.335372 0 -91.855932'] #

cmds.referenceQuery( "soffaRN", editNodes=True )
Result: [u'|kuddar:pillows1',
u'|model2670',
u'|kuddarRNfosterParent1|pillow_04',
u'|model2670|kuddar:pillows1',
u'|soffa:model2670',
u'|soffa:model2670'] #

cmds.referenceQuery( "soffaRN", editAttrs=True )
Result: [u'translate', u'rotate'] #

But I can’t seem to find a way to take any of those responses and actually
remove each edit.
Any ideas?

Regards,
Fredrik
​
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWPbYHapPht8F6Me8wtp8AgMC0m5%3DmdU7tcBGBWD%2BA4x0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Fredrik Averpil
2014-10-30 11:50:48 UTC
Permalink
And if it makes it easier to somehow solve this ... I'm looking to remove
*all* reference edits.


​
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWN0KiNbVzXWjC0PBZGHWqpWPPZN7KseMK1k6UwdqnoyDQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Luke Harris
2014-10-30 22:14:09 UTC
Permalink
I was doing this recently with pymel. Maya says that you can now remove ref
edits while the reference is loaded, but I've noticed this isn't always the
case, so I still unload it first for safety

for ref in pm.listReferences():
ref.unload()
for edit in ref.getReferenceEdits():
# this way you can selectively remove edits
pm.ReferenceEdit(edit, fileReference=ref).remove(force=True)
ref.load()

But if you want to remove ALL edits it might be faster to do a clean(),
which removes failed edits. If the ref is unloaded then all edits are
failed :)
for ref in pm.listReferences():
ref.unload()
ref.clean()
ref.load()
Post by Fredrik Averpil
And if it makes it easier to somehow solve this ... I'm looking to remove
*all* reference edits.
​
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2ee0b079-d794-4d84-956e-d465ae245e22%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Fredrik Averpil
2014-10-31 07:36:49 UTC
Permalink
Hi Luke, this is very useful.

I save out all the edits to an editMB file before cleaning it. And when I
save out that file as well as when I re-apply it later down the road, Maya
crashes sporadically. Currently, I’m not unloading the reference when
performing the edits export and the edits import. Perhaps that could be why
it’s crashing on me? (it’s not always crashing)

Your pymel examples looks really clean. I managed to do it without pymel,
but it’s a bit more cumbersome. I wonder if pymel is a more stable way of
dealing with this?

Here’s what I did to remove all edits (on a loaded reference):

# Remove all edits
ref = 'myrefRN'
nodes = cmds.referenceQuery( ref, editNodes=True )
attr_types = cmds.referenceQuery( ref, editAttrs=True )
for node in nodes:
for attr_type in attr_types:
for edit_command in ['addAttr', 'connectAttr',
'deleteAttr', 'disconnectAttr', 'parent', 'setAttr', 'lock',
'unlock']:
cmds.referenceEdit( node+'.'+attr_type,
failedEdits=True, successfulEdits=True, removeEdits=True,
editCommand=edit_command)

// Fredrik



On Thu, Oct 30, 2014 at 11:14 PM, Luke Harris <***@gmail.com> wrote:

I was doing this recently with pymel. Maya says that you can now remove ref
Post by Luke Harris
edits while the reference is loaded, but I've noticed this isn't always the
case, so I still unload it first for safety
ref.unload()
# this way you can selectively remove edits
pm.ReferenceEdit(edit, fileReference=ref).remove(force=True)
ref.load()
But if you want to remove ALL edits it might be faster to do a clean(),
which removes failed edits. If the ref is unloaded then all edits are
failed :)
ref.unload()
ref.clean()
ref.load()
Post by Fredrik Averpil
And if it makes it easier to somehow solve this ... I'm looking to remove
*all* reference edits.
​
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/2ee0b079-d794-4d84-956e-d465ae245e22%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/2ee0b079-d794-4d84-956e-d465ae245e22%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
​
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWPi2QNvFbVDzp-P2v0dim5F-Ewd7Yf0ZK9Y%2Bt5Z4J6P5w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Fredrik Averpil
2014-10-31 07:39:01 UTC
Permalink
Whoops 
 I meant to write that Maya crashes when I export the editMB
(sometimes) and later down the road it also crashes (sometimes) when I save
down the edits into the actual scene (“Save reference edits”).

By the way, this is how I save down the reference edits on a loaded
reference:

filepath = '..............'
cmds.file(filepath, saveReference=True, force=True)

​
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWNj_9tCTkjnmpHvU9CYO4b5iEY-cvA4zK%2BSZDq-51D2jg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Marcus Ottosson
2014-10-31 07:57:58 UTC
Permalink
Crashing reference updates is surprisingly common I think. One stable way
I've gone about it in the past is to update the .ma file. The results are
the same, except Maya won't have to keep the old and new reference in
memory while switching; which has been, in my experience, the cause of the
majority of crashes.
Post by Fredrik Averpil
Whoops 
 I meant to write that Maya crashes when I export the editMB
(sometimes) and later down the road it also crashes (sometimes) when I save
down the edits into the actual scene (“Save reference edits”).
By the way, this is how I save down the reference edits on a loaded
filepath = '..............'
cmds.file(filepath, saveReference=True, force=True)
​
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWNj_9tCTkjnmpHvU9CYO4b5iEY-cvA4zK%2BSZDq-51D2jg%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWNj_9tCTkjnmpHvU9CYO4b5iEY-cvA4zK%2BSZDq-51D2jg%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
*Marcus Ottosson*
***@gmail.com
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOANgFV6Yun1i2vdFLpKVjKnA15JAwqCXCZaRm6UMqaG-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Fredrik Averpil
2014-10-31 08:15:05 UTC
Permalink
One stable way I've gone about it in the past is to update the .ma file.
How do you mean, exactly?
Do you mean launching a separate process such as maya -batch -command "[mel
code]" -file hello.ma or do you mean reading in the .ma contents and
modifying it with Python?
​
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWP4t8znzmfXR9c-c2O-%3DmqreigKuKsbW%3DHG8K3%3DH8xcPQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Marcus Ottosson
2014-10-31 08:27:51 UTC
Permalink
You can either modify the .ma in a text-editor, as it is text, or through
Python via something like regular expressions. Each reference will be
clearly prefixed by it's unique command in the header of the file, along
with its absolute path.
Post by Fredrik Averpil
One stable way I've gone about it in the past is to update the .ma file.
How do you mean, exactly?
Do you mean launching a separate process such as maya -batch -command
"[mel code]" -file hello.ma or do you mean reading in the .ma contents
and modifying it with Python?
​
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWP4t8znzmfXR9c-c2O-%3DmqreigKuKsbW%3DHG8K3%3DH8xcPQ%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWP4t8znzmfXR9c-c2O-%3DmqreigKuKsbW%3DHG8K3%3DH8xcPQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
*Marcus Ottosson*
***@gmail.com
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOChbuv2ti4%3DPHD35xnUG%3DXgon7WUjybGV%3D9rjOg6a%2BRvA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Eduardo Grana
2014-10-31 10:56:33 UTC
Permalink
Hello Fredrik,
Regarding the remove all edits,
have you tryed the referenceEdit command with the flag
*removeEdits?*probably is safer, but you have to unload the reference first.
Cheers!
Eduardo
Post by Marcus Ottosson
You can either modify the .ma in a text-editor, as it is text, or through
Python via something like regular expressions. Each reference will be
clearly prefixed by it's unique command in the header of the file, along
with its absolute path.
Post by Fredrik Averpil
One stable way I've gone about it in the past is to update the .ma file.
How do you mean, exactly?
Do you mean launching a separate process such as maya -batch -command
"[mel code]" -file hello.ma or do you mean reading in the .ma contents
and modifying it with Python?
​
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWP4t8znzmfXR9c-c2O-%3DmqreigKuKsbW%3DHG8K3%3DH8xcPQ%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWP4t8znzmfXR9c-c2O-%3DmqreigKuKsbW%3DHG8K3%3DH8xcPQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
*Marcus Ottosson*
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOChbuv2ti4%3DPHD35xnUG%3DXgon7WUjybGV%3D9rjOg6a%2BRvA%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOChbuv2ti4%3DPHD35xnUG%3DXgon7WUjybGV%3D9rjOg6a%2BRvA%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
Eduardo Graña
www.eduardograna.com.ar
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CACt6GrnruvD9-gCB2B0hsPAJhFSDj-3JALSuw-3aY7brkDhK8A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Fredrik Averpil
2014-10-31 15:58:44 UTC
Permalink
Yes, however, that just simply does not work at all.

Try this;

for ref in cmds.ls(references=True):
cmds.referenceEdit( ref, removeEdits=True)

Here in my scene, nothing happens. No reference edits was removed.



On Fri, Oct 31, 2014 at 11:56 AM, Eduardo Grana <***@gmail.com>
wrote:

have you tryed the referenceEdit command with the flag *removeEdits?*
​
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWP3ow98GjVjpcArMwg7SbL6ZAuH0AoJhOzG76%2BQoZ6omg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Eduardo Grana
2014-10-31 16:13:51 UTC
Permalink
Hey Fredrik,
Your right, it doesn't do anything! hahaha

try this:


import maya.cmds as cmds

for ref in cmds.ls(references=True):
cmds.file(unloadReference=ref)
cmds.file (cr=ref) # *cleanReference*

thats how the reference editor does it...
(C:/Program Files/Autodesk/Maya2013/scripts/others/referenceEditorPanel.mel)

Cheers!
Eduardo
Post by Fredrik Averpil
Yes, however, that just simply does not work at all.
Try this;
cmds.referenceEdit( ref, removeEdits=True)
Here in my scene, nothing happens. No reference edits was removed.
have you tryed the referenceEdit command with the flag *removeEdits?*
​
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWP3ow98GjVjpcArMwg7SbL6ZAuH0AoJhOzG76%2BQoZ6omg%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWP3ow98GjVjpcArMwg7SbL6ZAuH0AoJhOzG76%2BQoZ6omg%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
Eduardo Graña
www.eduardograna.com.ar
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CACt6GrnMiidVGDFORwvR%3D%3DbMaByMQw-8zOSJUV-HT1Rc5DELpg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Fredrik Averpil
2014-10-31 16:42:30 UTC
Permalink
Aaahhh... yes, that did work. Thank you!
Post by Eduardo Grana
import maya.cmds as cmds
cmds.file(unloadReference=ref)
cmds.file (cr=ref) # *cleanReference*
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWMQ9muBsgunqChNeWM2AEKHW0wRo0d%2BwyTKx2Zo_WM3Yg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
g***@thelittlegiantz.com
2018-10-09 11:42:12 UTC
Permalink
Post by Fredrik Averpil
Yes, however, that just simply does not work at all.
Try this;
cmds.referenceEdit( ref, removeEdits=True)
Here in my scene, nothing happens. No reference edits was removed.
have you tryed the referenceEdit command with the flag removeEdits?
​
Hi Frederik,

I faced the same issue with you, searching all over google. And i think i found the problem.

it seems you need to use failedEdits and successfulEdits flags into it.

ex: cmds.referenceEdit( ref, removeEdits=True, failedEdits =True, successfulEdits =True)


Good Luck !
Gemilang Rahmandhika
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/69a5c9e5-fcdd-4bb1-b5c0-1bd183cd21a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...