を見せたいここで使用したいと思い戦略の簡単な例です。これはicontextボタンではなく、ボタンを使用しますが、アイデアは同じです。構造はコピーしたい部分です。すべてが列にラップされています。拡張性のためにレイアウトされています。フィルタはテキストフィールドとボタンを持つRowLayoutです。すべてのボタンは、ボタンを表示/非表示にして拡大/縮小できる第2列のレイアウトです。
import maya.cmds as cmds
# some dummy commands. Not the use of "_", which is
# a lazy way to ignore the argument which Maya will
# add to all callback functions
def apple_command(_):
cmds.polyCube()
def orange_command(_):
cmds.polySphere()
def banana_command(_):
cmds.polyPlane()
window = cmds.window(title = "filter")
root = cmds.columnLayout()
# filter button and text field
header = cmds.rowLayout(nc=2)
filter_field = cmds.textField()
filter_button = cmds.button(label = 'filter')
cmds.setParent("..")
# hideable butttons
button_list = cmds.columnLayout()
# create a bunch of buttons, storing the name in a dictionary for easier filtering
# this is a dictionary with the label of the button and the commands you want to
# attach to the buttons
button_names = {
'apples': apple_command,
'oranges': orange_command,
'bananas': banana_comand,
'mangoes': apple_command,
'coconuts': orange_command,
'durians': banana_command
}
button_widgets = {}
for button_name, button_command in button_names.items():
button_widgets[button_name] = cmds.button(label = button_name, width = 160, c= button_command)
# in a real application you'd also make the buttons do something....
# this makes the filter button apply the filter
# defining it down here lets it 'remember' the name of the filter
# field and the contents of the button dictionary
def apply_filter(*_):
# get the current text in the filter field
filter_text = cmds.textField(filter_field, q=True, text=True)
# loop over the dictionary, setting the visiblity of the button
# based on the key and the filter
for key, value in button_widgets.items():
viz = True
if len(filter_text):
viz = filter_text.lower() in key.lower()
cmds.button(value, edit=True, visible = viz)
# now hook it too the button
cmds.button(filter_button, e=True, c= apply_filter)
cmds.showWindow(window)
は基本的に、あなたは何をすべきか、あなたが実際のGUIウィジェットにそれらをマッピングした辞書の中にボタンを作成している間、フィルタ可能な名前を収集することです。次に、フィルタに従って視界を設定して、全体をループすることができます。 columnLayout
では、視界を変更すると、ギャップを自動的に閉じます。
このトリックは、個々のコントロールを管理するのではなく、レイアウトを作成して同じ方法で表示/非表示でコントロールのセットに使用できます。
通常、コマンドは 'cmds.button(label = 'some label'、c = some_python_function)'のように適用されます。これについての詳細はこちら(https://theodox.github.io/2014/maya_callbacks_cheat_sheet) – theodox
ああ...私は強くbeginnningからPythonを学ぶことをお勧めしたいと思います。 MELは何か深刻なもので作業するのがはるかに難しく、今日ではPythonに比べてあなたのキャリアにとって貴重ではありません – theodox
私はまだ初心者メルがありがとう、少し理解しやすいです。私の目標はゆっくりとmelからPythonに移行することです。申し訳ありませんが、コマンドを追加すると、すべてのボタンに同じコマンドが作成されます。「リンゴ」ボタンでキューブが作成され、「オレンジ」ボタンで円錐が作成されます – skb