renaming a QStandardItem to its corresponding pymel object

148 views
Skip to first unread message

Padraig Ó Cuínn

unread,
Dec 17, 2015, 2:48:39 AM12/17/15
to Python Programming for Autodesk Maya


Hi again. 

so i have a little thingy i am working on ( a type of node renamer ) 

so far I manage to get everything working. I am on a Model / View GUI compared to the old QListWidget.

so my question is, is it doable to get the text of a QStandardItem in the Model pumped from a Pymel object


PasteBin Code:


so while I was pasting my pastebin, I had another 2 questions. 

1. How easy would it be to implement status changes of a rename, %s _object to %s _newobject .... Would i be able to just include it in the selectionchanged status or create a new connection.
2. As far as the renaming goes, it would be nice for the ui to maintain itself on certain changes, One i had in mind was the refresh functionality is it possible to swap its function and text on selecting an item in the model and it changes to rename and uses a renaming connection.

I know they are somewhat advanced subject and may go into metadata contexts but yeah :) you guys are super smart and I am just me haha.

Thank you again for your help

Padraig Ó Cuínn

unread,
Dec 17, 2015, 12:58:07 PM12/17/15
to Python Programming for Autodesk Maya
ive no idea where the last sentence came from haha

Justin Israel

unread,
Dec 17, 2015, 3:20:34 PM12/17/15
to python_in...@googlegroups.com
On Thu, Dec 17, 2015 at 8:48 PM Padraig Ó Cuínn <patchquin...@gmail.com> wrote:


Hi again. 

so i have a little thingy i am working on ( a type of node renamer ) 

so far I manage to get everything working. I am on a Model / View GUI compared to the old QListWidget.

so my question is, is it doable to get the text of a QStandardItem in the Model pumped from a Pymel object

Do you mean that you want to be able to take a QStandardItem instance, at some point in a slot/callback and be able to use a pymel object that is associated with it? There are a few ways you can approach this and all of them deal with storing more inforation on your QStandarItems. You can use setData() to store custom data such as the full dag path or even the pymel instance itself:

# a class constant
MayaObjectRole = QtCore.Qt.UserRole + 1
MayaPathRole = QtCore.Qt.UserRole + 2
...
def foo(self):
    ...
    item = QtGui.QStandardItem()
    item.setData(pyMelObject, self.MayaObjectRole)
    item.setData(dagPath, self.MayaPathRole)

def bar(self, anItem):
    pyMelObject = anItem.data(self.MayaObjectRole)
    dagPath = anItem.data(self.MayaPathRole)
 


PasteBin Code:


so while I was pasting my pastebin, I had another 2 questions. 

1. How easy would it be to implement status changes of a rename, %s _object to %s _newobject .... Would i be able to just include it in the selectionchanged status or create a new connection.

I don't see any renaming logic in your code. Are you talking about responding to renames that happen within Maya, that you want to track and respond to? Any of this stuff falls into the category of setting up MMessage callbacks through the Maya API, and responding to those event in your GUI
 
2. As far as the renaming goes, it would be nice for the ui to maintain itself on certain changes, One i had in mind was the refresh functionality is it possible to swap its function and text on selecting an item in the model and it changes to rename and uses a renaming connection.

Can you explain this question again? What do you mean by swapping its function? Under what condition would you want to swap the function from one to another? Can you give a specific example of how you see this happening?
 

I know they are somewhat advanced subject and may go into metadata contexts but yeah :) you guys are super smart and I am just me haha.

Thank you again for your help

--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d451ffe9-9f9f-4da4-bfdb-8c40e408a8d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Padraig Ó Cuínn

unread,
Dec 17, 2015, 3:58:18 PM12/17/15
to Python Programming for Autodesk Maya
Hi Justin,

I haven't added any renaming code yet to the script because I am not sure where to begin with it. My original thought was that I could use the selection as a base and use that though out the main code for everything but its proven hard to even find the right start to that end. What I wanted was to be able to grab the listItem and rename it in the model and then the changes update in mayas selected object. 

To Question 1 : Yes just as ive done with the selection change with the status bar i thought it would be nice to get a feedback message saying, I renames this to this.

to Question 2:  If i make a selection of the objects (instead of renaming inside the model) would it be possible to have the button change state and rename the objects instead of refreshing (once the objects in the model are selected). having just said that i realise that the lineEdit would have to be used to setText

Justin Israel

unread,
Dec 17, 2015, 4:10:23 PM12/17/15
to Python Programming for Autodesk Maya
You can either take the approach of calling into Maya directly, and letting your model respond to callbacks from Maya when things change, in order to update, which then triggers updates in your views. Or you can take the approach of only interacting with your model, which will then make change in Maya after updating its own items. 

Your view can watch for selection changes, of your view items, and provide different visible buttons, or different enabled actions in a context menu. One action could be a rename operation. Another could be a delete operation.  

--
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_m...@googlegroups.com.

Padraig Ó Cuínn

unread,
Dec 17, 2015, 4:17:46 PM12/17/15
to python_in...@googlegroups.com

How would I go about that. I wouldn't have to create a new model for the changes in the renaming would I?

Padraig

You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/XC9rqzRjw1w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA01Mm1X%2B5hpYGC1iVmJFk%3D7%2B%2BFM%2B2AOJXa5MzzqndLFbw%40mail.gmail.com.

Justin Israel

unread,
Dec 17, 2015, 4:29:05 PM12/17/15
to python_in...@googlegroups.com
No, you have one model. And that model is meant to track items in your Maya scene. You would just need to watch for changes in your Maya scene and update your model accordingly. 

Padraig Ó Cuínn

unread,
Dec 17, 2015, 5:23:54 PM12/17/15
to python_in...@googlegroups.com

Ok I'm glad about that. So I've still no idea how to.impliment the name change haha. Sorry all this QT and model view programming

Padraig

Justin Israel

unread,
Dec 17, 2015, 5:56:28 PM12/17/15
to python_in...@googlegroups.com
I would think an approach would be to add a MNodeMessage callback for each selected item you add to your model:

If the node gets renamed in Maya, you will get a callback and can update your own model item. This means that you can simply rename a node in your UI code, and the callback from Maya will keep your model in sync.

Padraig Ó Cuínn

unread,
Dec 18, 2015, 1:01:37 PM12/18/15
to python_in...@googlegroups.com

I tried that one but I keep getting kfailure or other killer errors. From a what I've read about kfailure it says it's due to having a second callback connected up to the one signal. But I've created sperate signals.

I also tried using addattributechanged and addtributeremovedoradded and got the same.

Is there a way I can hook this up to the statusbar successfully? 

Padraig

Padraig Ó Cuínn

unread,
Dec 21, 2015, 1:27:36 AM12/21/15
to Python Programming for Autodesk Maya
Hey again I was back to this after a while and I was wondering how I go about hooking the MDGMessage.addnoderemoved to the signal. Is this a plausible way of accessing the MMessages? 

Signal in constructor
itemRemoved = Signal(list)

connection from signal to statusBar
def update_statusbar2():
     txt
= '%s deleted.'
     
self.statusbar.showMessage(txt)
self.itemRemoved.connect(update_statusbar2)

emitting the signal
def emit_itemdeleted():
    self.itemRemoved.emit(
        pmc.selected())
OpenMaya.MDGMessage.addNodeRemovedCallback(
   
Node, update_statusbar2(),emit_itemdeleted())

according to the docs you give a node, a function and clientdata ( I think i have done that here. But even if this is correct wouldn't this mean that I only send the signal for the given Node (hardocded).

I am looking for a way to dynamically show the name of the removed item on the statusbar which is why I have pmc.selected there because i thought it would reflect on the signal and then show the MDGMessgae from that.

Any help along here would be great with some kind of reference of a snippet of code how i would tackle this. there is practically no help on line for any of this at all like it isn't used.

thanks

-Padraig


Justin Israel

unread,
Dec 23, 2015, 2:09:37 AM12/23/15
to Python Programming for Autodesk Maya

If you don't have specific nodes that you want to monitor (meaning you want to watch any node and not just the ones in your ui) then maybe you want to look at MDagMessage or MDGMessage?

http://docs.autodesk.com/MAYAUL/2014/ENU/Maya-API-Documentation/cpp_ref/class_m_dag_message.html#aec1c63360030ad4c4d85e0a19652904c

http://docs.autodesk.com/MAYAUL/2014/ENU/Maya-API-Documentation/cpp_ref/class_m_d_g_message.html#abc9426c46ee4abae884a8dca5a97929a

If you look at the signature of the functions, you will see that the client data parameter is NULL by default. That means you don't have to pass anything for that param. It is used to associate some kind of extra data with the callback, and that data will get transmitted later when the callback fires. But if you only want to know the name of the node that was removed, it looks like the callback that you register will receive the information (MDagPath of removed node, etc)

What you are currently doing isn't making much sense. Again you have a signal defined to emit with a list as a param. And yes you emit the signal, passing the current selection   with it. But your slot never uses it. It accepts no parameters. So I don't understand the purpose of how you have configured that signal/slot.

You can mostly keep doing what you have so far, but try a different message callback type, and actually accept the callback parameters that Maya wants to pass you for that callback type, so that it can tell you what was removed and you can display it in your status bar.

Justin


--
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_m...@googlegroups.com.

patchquinnanimation

unread,
Dec 30, 2015, 1:46:06 PM12/30/15
to python_in...@googlegroups.com
I'm just getting errors after errors haha. Maybe it's time to quit this.
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/XC9rqzRjw1w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2kcXnCTVZ1AX5CgGwUFVec2y_WnBjPHFjpT%2BZg5dWBXw%40mail.gmail.com.

Justin Israel

unread,
Dec 30, 2015, 7:01:39 PM12/30/15
to python_in...@googlegroups.com

If you have specific code that we can look at, we can continue to help. Just please make sure whatever you share is actual code and not a rough approximation.


Reply all
Reply to author
Forward
0 new messages