[Maya Python] Crush the contents of the script 3 ~ List unknown Plugins

Purpose of this article

We will deepen your understanding while checking the contents of your own tools one by one, and use them for future tool development. It is a continuation of the following series. The part that overlaps with 1 and 2 is omitted.

-[Maya Python] Crushing the contents of the script 1 ~ Camera Speed Editor -[Maya Python] Crushing the contents of the script 2 ~ list Notes

Tool overview

Deletes the plug-in loading information stored in the scene. If it takes a long time to read the file, please try it.

List the plugin information and delete only the checked information. listUnknownPlugins.gif

Full code

# -*- coding: utf-8 -*-
from maya.app.general.mayaMixin import MayaQWidgetBaseMixin
from PySide2 import QtWidgets, QtCore, QtGui
from maya import cmds
	
class Widget(QtWidgets.QWidget):
	def __init__(self):
		super(Widget, self).__init__()
		
		layout = QtWidgets.QGridLayout(self)

		label = QtWidgets.QLabel(
			u'A list of unknown plugins.\n'\
			u'Delete the checked plug-in.')
		layout.addWidget(label, 0, 0)
		
		treeView = TreeView()
		layout.addWidget(treeView, 1, 0, 1, 2)
		
		self.standardItemModel = StandardItemModel()
		treeView.setModel(self.standardItemModel)
		
		button = QtWidgets.QPushButton('Refresh')
		button.clicked.connect(self.refresh)
		layout.addWidget(button, 2, 0)
		
		button = QtWidgets.QPushButton('Remove')
		#Change the background color of the button
		button.setStyleSheet("background-color: red")
		button.clicked.connect(self.remove)
		layout.addWidget(button, 2, 1)
		
		self.refresh()
		
	#Operation of Refresh button
	def refresh(self):
		self.standardItemModel.removeRows(0, self.standardItemModel.rowCount())
		
		#List unknownPlugin
		unknownPluginList = cmds.unknownPlugin(q=True,list=True)

		#Returns False if there is no unknownPlugin
		if not unknownPluginList:
			return False
		
		#Add unknownPlugin to item
		for name in unknownPluginList:
			self.standardItemModel.appendItem(name)

		return True

	#The operation of the Remove button
	def remove(self):
		#Get row count
		count = self.standardItemModel.rowCount()

		#Repeat for row count
		for num in range(count):
			#Get check status and name
			(check,name) = self.standardItemModel.rowData(num)

			#If checked, delete unknownPlugin
			if check:
				cmds.unknownPlugin(name,remove=True)
				print (u'deleted %s\n'%(name)),
		
		#Update list contents
		self.refresh()
		
		
class TreeView(QtWidgets.QTreeView):
	def __init__(self):
		super(TreeView, self).__init__()		
		self.setSelectionMode(QtWidgets.QTreeView.ExtendedSelection)
		self.setAlternatingRowColors(True)
		#Changed to be able to sort
		self.setSortingEnabled(True)

		
class StandardItemModel(QtGui.QStandardItemModel):
	def __init__(self):
		super(StandardItemModel, self).__init__(0, 1)
		self.setHeaderData(0, QtCore.Qt.Horizontal, 'Plugin Name')
	
	def appendItem(self, name):		
		standardItem = QtGui.QStandardItem()
		standardItem.setText(str(name))
		standardItem.setEditable(False)
		#Add check items
		standardItem.setCheckable(True)
		#Check
		standardItem.setCheckState(QtCore.Qt.Checked)
		
		self.appendRow([standardItem])
	
	def rowData(self, index):
		check = self.item(index, 0).checkState()
		name  = self.item(index, 0).text()
				
		return (check,name)	


class MainWindow(MayaQWidgetBaseMixin, QtWidgets.QMainWindow):
	def __init__(self):
		super(MainWindow, self).__init__()

		self.setWindowTitle('List Unknown Plugins')
		self.resize(430, 260)

		widget = Widget()
		self.setCentralWidget(widget)


def main():
	window = MainWindow()
	window.show()
	
if __name__ == "__main__":
	main()

Let's see the details

Line breaks in the middle of the program

		label = QtWidgets.QLabel(
			u'A list of unknown plugins.\n'\
			u'Delete the checked plug-in.')

To start a new line in a long program, close it with ' and insert \ at the end. Then add ʻu` to the beginning of the line.

Change the color of the button

		#Change the background color of the button
		button.setStyleSheet("background-color: red")

Change the button color to red. It seems that you can also change the frame and do various things. This time, it is set to red with the meaning of calling attention to the action of erasing.

Qt Style Sheets Examples

The operation of the Remove button

	#The operation of the Remove button
	def remove(self):
		#Get row count
		count = self.standardItemModel.rowCount()

		#Repeat for row count
		for num in range(count):
			#Get check status and name
			(check,name) = self.standardItemModel.rowData(num)

			#If checked, delete unknownPlugin
			if check:
				cmds.unknownPlugin(name,remove=True)
				print (u'deleted %s\n'%(name)),
		
		#Update list contents
		self.refresh()

Get the number of rows and use range to count up. If count is 5, range (count) becomes 0,1,2,3,4, and check, name is obtained from each row number. If check is True, the plug-in information will be deleted and printed.

After processing all the steps, re-acquire the unknownPlugin with self.refresh and update the list contents.

Add a check item to an item

		#Add check items
		standardItem.setCheckable(True)
		#Check
		standardItem.setCheckState(QtCore.Qt.Checked)

Add a check item to the item so that you can check it. QStandardItemModel is convenient because you can add a check box for each item.

in conclusion

This time, I created it by diverting the script created below and partially modifying it. If you create a UI with PySide in this way, you will be able to create various scripts with only partial changes to the contents. When creating a Python script in Maya, please try creating a UI with PySide.

-[Maya Python] Crushing the contents of the script 1 ~ Camera Speed Editor -[Maya Python] Crushing the contents of the script 2 ~ list Notes

Recommended Posts

[Maya Python] Crush the contents of the script 3 ~ List unknown Plugins
[Maya Python] Crush the contents of the script 2 ~ list Notes
[Maya Python] Crush the contents of the script 1 ~ Camera Speed Editor
Template of python script to read the contents of the file
About the basics list of Python basics
A Python script that compares the contents of two directories
[Python] A program that rotates the contents of the list to the left
[Introduction to Python] How to sort the contents of a list efficiently with list sort
Get the contents of git diff from python
[Python] Sort the list of pathlib.Path in natural sort
The contents of the Python tutorial (Chapter 5) are itemized.
The contents of the Python tutorial (Chapter 4) are itemized.
The contents of the Python tutorial (Chapter 2) are itemized.
The contents of the Python tutorial (Chapter 8) are itemized.
The contents of the Python tutorial (Chapter 1) are itemized.
Make a copy of the list in Python
The contents of the Python tutorial (Chapter 10) are itemized.
The contents of the Python tutorial (Chapter 6) are itemized.
The contents of the Python tutorial (Chapter 3) are itemized.
Python script to get a list of input examples for the AtCoder contest
List of python modules
the zen of Python
[python] Get the list of classes defined in the module
Get the return code of the Python script from bat
Not being aware of the contents of the data in python
[Python] Get the list of ExifTags names of Pillow library
[Python] Outputs all combinations of elements in the list
Towards the retirement of Python2
Summary of Python3 list operations
About the ease of Python
Get the number of specific elements in a python list
[Python] Copy of multidimensional list
About the features of Python
[Data science memorandum] Confirmation of the contents of DataFrame type [python]
2015-11-26 python> Display the function list of the module> import math> dir (math)
Simulation of the contents of the wallet
The Power of Pandas: Python
How to connect the contents of a list into a string
Process the contents of the file in order with a shell script
[Python] Display only the elements of the list side by side [Vertical, horizontal]
[python, ruby] fetch the contents of a web page with selenium-webdriver
Output the contents of ~ .xlsx in the folder to HTML with Python
[python] Get the rank of the values in List in ascending / descending order
python note: map -do the same for each element of the list
List of disaster dispatches from the Sapporo City Fire Department [Python]
The story of Python and the story of NaN
Easy encryption of file contents (Python)
[Python] The stumbling block of import
[Python] [Table of Contents Links] Python Programming
Understand the contents of sklearn's pipeline
Existence from the viewpoint of Python
pyenv-change the python version of virtualenv
Get the script path in Python
Change the Python version of Homebrew
See the contents of Kumantic Segumantion
Python Math Series ⓪ Table of Contents
[Python] Understanding the potential_field_planning of Python Robotics
Review of the basics of Python (FizzBuzz)
Remove unknown plugins in the scene
Introductory table of contents for python3
Learn the basics of Python ① Beginners