On Thu, Jul 4, 2019 at 6:00 AM likage <dissidia....@gmail.com> wrote:
> Hi everyone, I am trying to make a real-time update, eg. a renaming > between maya scene and my tool. Previously I made a thread about it, but > seeing that it is a bit confusing, I have decided to make a new thread and > repost it with coding on what I am trying to achieve. > > Currently I am able to effect changes from my tool and modify the naming > in the scene. But in the event if I perform an undo in the maya scene > itself, the undo changes are not effected back into the tool. > > Here is my code: > > class Example(QtGui.QWidget): > def __init__(self, parent=None): > super(Example, self).__init__() > self.initUI() > self.setup_connections() > > def initUI(self): > self.setGeometry(300, 300, 300, 200) > self.setWindowTitle('Rename') > > self.list_widget = QtGui.QListWidget() > self.add_loc_btn = QtGui.QPushButton("Add new Locator") > > vlayout = QtGui.QVBoxLayout() > vlayout.addWidget(self.list_widget) > vlayout.addWidget(self.add_loc_btn) > vlayout.addStretch(1) > self.setLayout(vlayout) > > def setup_connections(self): > self.add_loc_btn.clicked.connect(self.add_locator) > > self.list_widget.itemDoubleClicked.connect(self.list_item_dbl_click) > self.list_widget.itemChanged.connect(self.list_item_click) > > def add_locator(self): > new_loc = cmds.spaceLocator() > loc_fp = cmds.ls(new_loc[0], long=True) > loc_item = QtGui.QListWidgetItem(str(new_loc[0])) > loc_item.setData(32, loc_fp[0]) > loc_item.setFlags( > loc_item.flags() | > QtCore.Qt.ItemIsUserCheckable | > QtCore.Qt.ItemIsEditable > ) > self.list_widget.addItem(loc_item) > > def list_item_dbl_click(self): > current_item = self.list_widget.currentItem() > self.prev_name = current_item.text() > self.rename_counter = 1 > > def list_item_click(self, test): > success = False > current_item = self.list_widget.currentItem() > list_item_row = self.list_widget.currentRow() > new_name = current_item.text() > > if self.validate_naming(new_name): > locator = current_item.data(32) > if cmds.objExists(locator) and self.rename_counter == 1: > cmds.select(locator) > cmds.rename(new_name) > > # reset counter back to 0 > self.rename_counter = 0 > success = True > > else: > # Set back to its initial naming before rename > current_item.setText(self.prev_name) > > if success: > list_item = self.list_widget.item(list_item_row) > self.list_widget.setCurrentItem(list_item) > > def validate_naming(self, name_input): > if re.search("^\s*[0-9]", name_input): > LOG.warning("Input naming cannot be started off with numbers!") > return False > return True > > > myWin = Example() > myWin.show() > > Here are some steps to reproduce: > > - Click on the ‘Add new Locator’ button > - It will creates a locator1 in the scene and populated in the list > widget > - Double click on the locator1 in the list widget and input in a new > name. Eg. ‘myLocator’ > - Go back to Maya and tried pressing ‘Ctrl+Z’ (undo) > - While it does changes the name ‘myLocator’ back to ‘locator1’ in > Maya context, I would also like it to be ‘updated’ in my Gui. > > How should I go about doing this? > P.S: I was also trying to find a way to peform undoing in the Gui which > will also in turns effects the changes in the Maya scene if possible. > Have you tried using a MEventMessage or a scriptJob to listen for the "Undo" Maya events and then performing the undo in your own GUI? > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/63af8ecf-5d67-4004-a076-34fc68019d9f%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/63af8ecf-5d67-4004-a076-34fc68019d9f%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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2_RckBCTOR5N7O0S7oAtFG3BRrpWSQcN%2BoNN4Lyb1dLw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.