Exemple #1
0
    def select_ncloth_outliner_item_from_dock_widget(self, dock_widget):
        """
        Selects nodes in the nclothOutliner that are selected in the Maya scene
        """
        # Get the selection model of the TreeView and initiate an empty item selection
        selection_model = self.selectionModel()
        selection = QtCore.QItemSelection()

        # print "dock_widget_tree_view:", type(dock_widget_tree_view), dock_widget_tree_view
        # dock_widget = dock_widget_tree_view.parent()
        print "dock_widget:", type(dock_widget), dock_widget
        dock_widget_mobj = dock_widget.mobj
        print "dock_widget_mobj:", type(dock_widget_mobj), dock_widget_mobj

        ncloth_outliner_item = self.find_item_by_mobj_with_path(
            dock_widget_mobj)
        if ncloth_outliner_item is None:
            return False

        # Otherwise: Find the index of the found item...
        index = self.model().indexFromItem(ncloth_outliner_item)
        # ...and append the item to the selection model (must be via ItemSelectionRange)
        selected_item = QtCore.QItemSelectionRange(index)
        selection.append(selected_item)

        # Finally: Clear the current selection and select the new itemSelection
        selection_model.select(selection,
                               QtCore.QItemSelectionModel.ClearAndSelect)
Exemple #2
0
    def select_ncloth_outliner_items_from_scene_selection(self):
        """
        Selects nodes in the nclothOutliner that are selected in the Maya scene
        """
        # Get the selection model of the TreeView and initiate an empty item selection
        selection_model = self.selectionModel()
        selection = QtCore.QItemSelection()

        # Go through all mobjs that are currently selected in the Maya scene
        for selected_mobj in MUtil._selected_nodes_in_scene_as_mobjs():
            # Try to match the selected mobj to any outliner item (using their long name)
            ncloth_outliner_item = self.find_item_by_mobj_with_path(
                selected_mobj)
            if ncloth_outliner_item is None:
                # If the mobj itself couldn't be found: try its shape!
                shape_mobj = MUtil._get_shape_mobj(selected_mobj)
                ncloth_outliner_item = self.find_item_by_mobj_with_path(
                    shape_mobj)

            # If no outliner-item was matched: continue
            if ncloth_outliner_item is None:
                continue

            # Otherwise: Find the index of the found item...
            index = self.model().indexFromItem(ncloth_outliner_item)
            # ...and append the item to the selection model (must be via ItemSelectionRange)
            selected_item = QtCore.QItemSelectionRange(index)
            selection.append(selected_item)

        # Finally: Clear the current selection and select the new itemSelection
        selection_model.select(selection,
                               QtCore.QItemSelectionModel.ClearAndSelect)