这里介绍一个制作一个属于自己的快速选择工具。我们可以事先编辑快速选择的规则,然后下次相同规则的模型进来,能够快速批量选择需要的对象,比如控制器等。我们在为绑定角色制作动画的时候,一个人物模型存在大量的控制器。动画师有时候想一次性选中全部手指的控制器或者整个手臂的控制器。这个时候有个快速批量选择的工具,那动画师的工作效率就会提高很多。

这里是我这制作的界面,选择模式是一个下拉列表,不同的模式里面可以添加不同的选择组。因为可能不同的绑定规则,控制器命名方式是不一样的。所以我们添加一个模式的选择。
模式我们可以添加,每一个模式我们会把描述信息写入一个文件,这样就实现了我们的保存,下次打开的时候能够直接把自己添加的模式和选择组自动导入进来。同时我们也支持把现有的模式进行修改,然后把修改的内容会写进入配置文件中。这里的配置文件使用的是json,因为能Python和Json能够很方便的快速互转,这是我们的首选。
5.3.1 Json文件结构
{
"CurrentMode": "Adv",
"ModeData": [
{
"list": [
{
"button": "\u5de6\u624b\u81c2",
"rule": [
"FKShoulder_L",
"FKElbow_L",
"FKWrist_L"
]
},
{
"button": "\u53f3\u624b\u63a7\u5236\u5668",
"rule": [
"FKPinkyFinger1_R",
]
}
],
"name": "Adv"
}
]
}
上面是我的存储文件结构,这个根据自己的需求和习惯自己设计即可。这里我来解释一下我为什么这样设计。
CurrentMode:这是当前选中的模式。因为我们下次打开此界面的时候,能够优先选中我们上次关闭时的选择。
ModeData:这是一个数组,每个数组对象是一个模式信息对象。
list:存放我们选择组的按钮信息,里面包括按钮的名字,按钮要选择的对象名字。
button:按钮的名字。
rule:需要选择的对象名字。
name:模式的名字。
5.3.2 解析配置文件
现在我们解析上面的配置文件,首先读取文件数据,把读取的字符串通过json库解析成Python对象。然后根据里面的信息初始化我们的模式Combox控件和按钮组。
def initMode(self):
self.ui.modeModifyBtn.setEnabled(False)
curPath = self.GetCurrentDir()
ruleFile = curPath + '/rule.json'
if not os.path.exists(ruleFile):
return
with open(ruleFile,'r') as inFile:
data = json.load(inFile)
self.Data = data
self.curtName = self.Data['CurrentMode']
self.initModeComBox()
self.refreshButtons()
def initModeComBox(self):
if self.Data == None:
return
self.ui.modeCombox.clear()
for k in self.Data['ModeData']:
name = k['name']
if self.ui.modeCombox.findText(name) < 0:
self.ui.modeCombox.addItem(name)
self.ui.modeCombox.setCurrentText(self.curtName)
if self.curtName == '':
self.curtName = self.ui.modeCombox.currentText()
if self.ui.modeCombox.currentText() != '':
self.ui.modeModifyBtn.setEnabled(True)
else:
self.ui.modeModifyBtn.setEnabled(False)
def clearButtons(self):
for k in self.buttons:
self.ui.gridLayout.removeWidget(k)
k.setParent(None)
self.buttons = []
def refreshButtons(self):
self.clearButtons()
if self.Data == None:
return
item = self.findItem(self.Data,self.curtName)
if not item:
return
row = 0
col = 0
mo = 2
for n in item['list']:
button = QuickSelectRuleButton.QuickSelectRuleButton()
button.setRule(n['button'],n['rule'])
self.ui.gridLayout.addWidget(button,row,col % mo)
self.buttons.append(button)
col += 1
if col == mo:
row += 1
col = 0
这上面的代码都很简单,就是读取配置数据,然后动态创建对应的控件和还原控件中的数据。这里我们实现了一个自己的按钮QuickSelectRuleButton,这样我们方便响应自己的响应函数。
5.3.3 自定义控件
有时候为了方便,我们会实现一些自定义控件。比如我们这里想扩展一下我们的QPushButton,这样我们就能自定一些属性进去,然后方便我们操作。
# QuickSelectRuleButton.py
from PySide2 import QtWidgets, QtCore, QtGui
from PySide2.QtCore import Qt
import pymel.core as pm
class QuickSelectRuleButton(QtWidgets.QPushButton):
def __init__(self):
super(QuickSelectRuleButton, self).__init__()
self.rule = []
self.clicked.connect(self.onClick)
def setRule(self,name,rule):
self.rule = rule
self.setText(name)
def checkMatch(self,nodeName):
for k in self.rule:
if nodeName.endswith(k):
return True
return False
def onClick(self):
nodes = pm.ls()
for k in nodes:
if self.checkMatch(k.name()):
pm.select(k.name(),add=1)
我们自定义的按钮,我们可以把选择规则设置进来,点击的响应就自动完成了,没必要我们使用QPushButton原生的按钮,每个按钮再单独设置点击响应。这里我们使用的是继承QPushButton来实现功能的扩展。
5.3.4 模式创建

上图是我们创建模式的一个窗口面板截图。我们有设置模板的名字,然后+号按钮是添加一个按钮,我们知道一个按钮代表一到多个的选择,所以我们需要创建一个空间,里面能设置按钮的名字和按钮选择的对象名字。
def onAdd(self):
itemWidget = QuickSelectRuleItem.QuickSelectRuleItem()
itemWidget.setDelCallBack(self.delItemCallBack)
item = QtWidgets.QListWidgetItem(self.ui.modeListWidget)
item.setSizeHint(QtCore.QSize(0, 123));
self.ui.modeListWidget.addItem(item)
self.ui.modeListWidget.setItemWidget(item,itemWidget)
self.itemList[itemWidget] = item

这里也很简单,我们需要知道怎么提取我们当前选中的对象的名字:
def onSel(self):
nodes = pm.selected()
for n in nodes:
name = n.name()
ix = name.rfind(':')
if ix > -1:
name = name[ix+1:]
self.ui.ruleNodesText.append(name)
我们使用rfind找到最后一个冒号,为了是把我们名字上的命名空间去掉。我们在选择的时候是不管命名空间的。
5.3.4 写配置文件
当我们点击确定按钮的时候,我们要把当前的内容保存出去,也就是把我们视图数据存储出去。上面已经介绍了我们配置文件的结构,我们构建出这样的对象即可。
def onOk(self):
curPath = self.GetCurrentDir()
ruleFile = curPath + '/rule.json'
data = {}
if os.path.exists(ruleFile):
with open(ruleFile,'r') as inFile:
data = json.load(inFile)
inFile.close()
else:
data['CurrentMode'] = ''
data['ModeData'] = []
ruleName = self.ui.modeNameEdit.text()
if ruleName == '':
QtWidgets.QMessageBox.warning(self,'warning','需要设置名字',QtWidgets.QMessageBox.Ok)
return
if len(self.itemList) == 0:
QtWidgets.QMessageBox.warning(self, 'warning', '需要至少选择一个对象', QtWidgets.QMessageBox.Ok)
return
if self.checkSame(data,ruleName):
QtWidgets.QMessageBox.warning(self, 'warning', '名字重复,请重新设置', QtWidgets.QMessageBox.Ok)
return
item = {}
item['name'] = ruleName
item['list'] = []
for t in self.itemList:
ruleName = t.getRuleName()
nodeNames = t.getNodeNames()
if ruleName == '' or len(nodeNames) == '':
continue
item['list'].append({'button':ruleName,'rule':nodeNames})
data['ModeData'].append(item)
jsonStr = json.dumps(data, indent=2, sort_keys=True)
with open(ruleFile,'w') as outFile:
outFile.write(jsonStr)
outFile.close()
if self.okCallBack:
self.okCallBack()
self.close()
好了,这个里面的新知识点很少,都是前面介绍的综合使用。下面附上完整的代码:
Seo Marketing Company
Having read this I thought it was extremely enlightening. I appreciate you finding the time and energy to put this article together. I once again find myself spending a lot of time both reading and commenting. But so what, it was still worthwhile!
RV Collision Repair Shop Near Me
Oh my goodness! Impressive article dude! Thank you, However I am experiencing difficulties with your RSS. I donít know the reason why I can’t subscribe to it. Is there anybody else getting the same RSS issues? Anyone who knows the answer can you kindly respond? Thanx!!
Seo Marketing Expert
This is a topic which is close to my heart… Best wishes! Where are your contact details though?
Internet Marketing Store
This is a topic that’s near to my heart… Thank you! Where are your contact details though?
RV Paint Shop Services By My Location
Hi there! I simply wish to give you a huge thumbs up for the great information you have right here on this post. I am coming back to your blog for more soon.
WimMut
buy amoxicillin online
RV Reupholstering Near Me
An interesting discussion is worth comment. I do believe that you need to publish more on this issue, it might not be a taboo matter but typically folks don’t talk about such subjects. To the next! Kind regards!!
RV Plumbing Repair Orange County
I could not resist commenting. Well written!
zmozeroteriloren
Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something. I think that you can do with a few pics to drive the message home a little bit, but other than that, this is great blog. A fantastic read. I’ll certainly be back.
Facebook Ads Guide
Pretty! This was an incredibly wonderful post. Thank you for supplying this info.
Online Marketing Companies
After checking out a number of the blog posts on your web site, I honestly appreciate your way of writing a blog. I book-marked it to my bookmark webpage list and will be checking back in the near future. Take a look at my website as well and tell me your opinion.
ElwoodVok
albuterol 108 mcg
fountee
16 Clark TJ, Mann CH, Shah N, Song F, Khan KS, Gupta JK stromectol cena
joyboanny
can i buy priligy over the counter They also suggest that an LTT approach could be developed for any small, lipophilic molecule with good dermal permeation, thus greatly expanding the menu of drugs that could be tested for breast cancer prevention
actiole
will nolvadex raise testosterone meeting By Josh Mitchell Staff reporter The City Council is still considering raising rates for water, sewer and garbage to meet budget shortfalls in the fiscal year that begins July 1
RV Maintenance Orange County
Oh my goodness! Impressive article dude! Thank you so much, However I am having problems with your RSS. I donít know why I am unable to subscribe to it. Is there anyone else getting identical RSS problems? Anyone that knows the solution will you kindly respond? Thanks!!
Camper Restoration Near Me
Hi, I do think this is an excellent web site. I stumbledupon it 😉 I may return yet again since I bookmarked it. Money and freedom is the best way to change, may you be rich and continue to help other people.
NFT Newsstand
You are my inspiration , I own few web logs and sometimes run out from to post .
enviple
Wheatley KE, Nogueira LM, Perkins SN, Hursting SD Differential effects of calorie restriction and exercise on the adipose transcriptome in diet induced obese mice zinc and zithromax hey everyone, I am so glad I found this website
RV Generator Repair Service Near Me
The next time I read a blog, Hopefully it does not disappoint me just as much as this one. After all, I know it was my choice to read through, however I truly thought you would have something useful to talk about. All I hear is a bunch of crying about something you could possibly fix if you weren’t too busy looking for attention.
RV Interior Remodeling Near Me
Itís hard to come by knowledgeable people about this subject, but you seem like you know what youíre talking about! Thanks
RV Shop Near Me
Pretty! This was an incredibly wonderful article. Many thanks for providing this information.
Cicaimb
The interaction between drugs and gut microbe composition is important for understanding drug mechanisms and the development of certain drug side effects 1, 2 propecia online australia
The Best Places to do Work Experience Zhoushan (China)
An interesting discussion is worth comment. I think that you should write more on this topic, it might not be a taboo subject but generally people are not enough to speak on such topics. To the next. Cheers
Beginners Guide on How to Breed Silver Fox - Rabbits (Beginners Guide)
Very interesting topic, thanks for putting up.
Learning and Understanding about Barth syndrome Disease (Volume 1)
Only wanna remark that you have a very decent internet site, I love the pattern it actually stands out.
The Best Dessert Places in Lianyuan (China)
hi!,I like your writing so much! proportion we keep in touch more about your post on AOL? I require an expert on this space to resolve my problem. May be that is you! Taking a look forward to see you.
How to Start a Coal Preparation (opencast) Business (Beginners Guide)
I?¦ve been exploring for a little for any high-quality articles or weblog posts in this kind of house . Exploring in Yahoo I at last stumbled upon this site. Reading this info So i?¦m glad to exhibit that I have a very excellent uncanny feeling I came upon just what I needed. I most unquestionably will make certain to do not put out of your mind this site and provides it a glance on a continuing basis.
How to Write a Business Plan for a Geophysical Test Drilling, Test Boring And Core Sampling Business
Absolutely written articles, Really enjoyed examining.
Top Places to Eat in Brisbane (Australia)
It’s in point of fact a great and helpful piece of information. I’m happy that you simply shared this helpful info with us. Please stay us informed like this. Thank you for sharing.
JaneMut
generic flomax capsules
Beginners Guide to Growing Petroselinum (parsley) (Home & Garden Handbook)
Excellent blog here! Also your web site loads up very fast! What host are you using? Can I get your affiliate link to your host? I wish my website loaded up as quickly as yours lol
Sprinter Van Inside Computer Repair Shop
Reach your goals, obtain even more done and also enhance your life!
Timothyhop
zoloft no prescription
WimMut
azithromycin from india
Dodge Sprinter Service Centers
Amazingness can give that for you!
JudyMut
herpes medication valtrex
ZakMut
gabapentin 200 mg tablets
RV Interior Remodel In California
Just how? Figure out now!
MiaMut
generic synthroid 200 mcg
MichaelMix
lasix no prescription
CarlMut
furosemide 40 mg daily
Marvinwes
how much is colchicine in canada
YonMut
44022 lasix
MiaMut
generic flomax online
fire truck repair near me
Discover the very best behaviors of effective people.
JasonMut
valtrex brand name price
best rv
You may find that you are doing every little thing faster, much better and also much more efficiently than ever in your life!
RV Repair
Amazingness is a productivity booster that will certainly change your life for the better!
camper repair shop near me
Begin living your finest life now with the phenomenal!
MarkMut
online pharmacy ed
motorhome repair shop near me
Achieve every one of your most important things faster and also easier!
Mercedes Sprinter Van Near Me
You are entitled to the best of every little thing in life. And this product can assist you arrive!
ford transit van camper conversion kits
Amazingness can help you be more effective, focused as well as live a healthier life!
auto repair shop near me
Extraordinary is a innovative technique for getting more done daily.
Van Transportation Services Near Me
Have a good time and obtain things made with the most fantastic device!
YonMut
diclofenac 150 mg tablets
SueMut
canadian pharmacy 24 com
paint repair shop
You ‘d be in awe of just how good this goes to what it does!
interior conversion kits for the chevy astro van
The Incredible method to transform your life for the better!
the repair shop location
Sign up currently and get going on your trip today!
wheelchair ramps van conversion kits
Incredible is an all-in-one life management tool that will certainly aid you stay on top of your to-dos, goals, as well as schedule.
trailer axle repair near me
Find out exactly how amazingness sustains your service development with the remarkable power it holds.
Camper Service Near Me
Every little thing you need is right below!
Sprinter Van Window Installation Near Me
Begin feeling fantastic today by living the life that you’ve constantly wanted!
frame repair shop
End up being a master in everything with this!
Robertcoups
strattera generic price
NickMut
where can i buy propecia without a prescription
rv slide repair near me
Amazing is the one stop look for whatever performance.
horse trailer roof replacement
Remarkable is a life changing tool that will certainly aid you be more effective as well as improve outcomes.
Contact Us For Map
Be the best at everything you do!
EstebanUnlag
generic strattera usa
Visit Website Colors
Incredible will provide you a lot of outstanding possibilities.
Go Here Photos
Amazing advantages for you, friends and family that keep giving.
Alton Maltba
The Amazingness life performance system gives you more time and energy to do what you love.
Website Images
This simply may be the life-changing product you have actually been waiting on.
CarlMut
furosemide 20 mg over the counter
EdgarTex
us trazodone cost
AnnaMut
prednisone 7.5 mg daily
NickMut
finasteride online 1mg
KimMut
gabapentin generic price
AmyMut
1600 mg gabapentin
AshMut
brand name amoxicillin capsule
MichaelMix
generic diflucan 150 mg
LisaMut
buy fluconazol without prescription
Dodge Sprinter Parts Near Me
This can do the technique!
CurtisRog
augmentin best price
Sprinter Near Me
Amazingness is a performance booster that will certainly transform your life right!
Class A Motorhome Repair Near Me
Have a look at just how this tool can alter your life right!
Mobile Rv Tech Near Me
Get one year free plus up to 40 off your first registration!
MiaMut
sildenafil tablets 100 mg
JackMut
prednisolone 3 mg
Samuelkit
1 mg prednisone daily
TeoMut
robaxin over the counter canada
EvaMut
average cost of ciprofloxacin
Michaeldub
valtrex tablets over the counter
MarkMut
buy cipro
CurtisRog
rx pharmacy no prescription
CarlMut
cipro over the counter mexico
NickMut
zovirax capsule
MichaelMex
lyrica 325 mg
MiclEndah
synthroid 300 mcg tablets
mezőgazdasági pályázatok kezdőknek
I simply wished to appreciate you once more. I’m not certain the things I would have used in the absence of the tricks shared by you relating to such problem. It previously was a real alarming crisis in my view, nevertheless being able to view the expert strategy you processed that forced me to jump for happiness. I’m just grateful for the work and then wish you are aware of a powerful job that you’re doing educating other individuals through the use of your web site. More than likely you’ve never encountered any of us.
JackMut
how can i get retin a cream
JaneMut
azithromycin where can i buy
KimMut
cipro 94
EvaMut
cafergot internet pharmacy
Van Service Center
Phenomenal is the best efficiency device for busy individuals who want to get more done in much less time.
RV Body Repair Shops
Check out exactly how this set device can change your life right!
JackMut
zanaflex 4mg capsule price
JackMut
baclofen 10 mg tabs
EstebanUnlag
motilium for breastfeeding
Rodneyteala
generic priligy 60 mg
TeoMut
buy sildenafil 20 mg
Motorhome Collision Repair Shop
Discover exactly how to maintain your home tidy as well as tidy in 30 minutes!
Marvinwes
buy lexapro
JaneMut
proscar 1mg tablets
vape places near me
Be the very best at every little thing you do!
injury lawyer
The Incredible means to change your life for the better!
dodge sprinter repair
Unbelievable advantages for you, friends and family that continue giving.
UgoMut
cafergot tablets in india
ZakMut
buy malegra 100
JaneMut
cheap doxycycline online uk
KiaMut
tizanidine online without prescription
JackMut
fluoxetine 40 mg prices
KiaMut
zanaflex tab 4mg
handicapped van repair
Obtain all you need and also much more with this!
Juseshext
Same thing with that if you put in a little in today, a little in tomorrow, you know, gradually, step by step, you ll get what you re looking for without INAUDIBLE towards just messing yourself up 10mg nolvadex during cycle
Timothyhop
how to buy cafergot
NickMut
price of strattera
EstebanUnlag
tretinoin cream online
KimMut
canadapharmacyonline com
pippeferi
None of the patients with renal amyloidosis had any preexisting or coexisting illness doxycycline coronavirus
YonMut
prozac 40 mg
YonMut
25 mg atarax
CarlMut
celebrex
DavidLed
retin a price canada
Toshiko Hillie
Incredible is the performance application that will alter your life.
EvaMut
motilium buy in canada online
MichaelMex
toradol over the counter canada
Jessi Knaust
This is something that every family and also organization requirements.
Rodneyteala
cheap propecia
Kirk Barners
Be better, much more innovative, and extra efficient!
JaneMut
ventolin price canada
Gregoria Terranova
It’s that time once again to obtain every little thing performed in a really short time period.
Rodneyteala
albuterol 5 mg
EvaMut
cheap viagra online canadian pharmacy
JasonMut
buy gabapentin online cheap
Major Metzler
You deserve this!
pippeferi
I thought it was over and was looking forward to trying again most reliable site to buy clomid clomid ondansetron 8mg odt Non oil re exports from the city state, for instance, grew14