Home  Previous Next

You can post your question in MG-Picker Studio Q&A board and get the answer from us.

Q: How to avoid hard-coding the picker item id?

To get the id of the current picker item, say you are editing the command of command button of the id called "commandButton1", within that command script,

you can use this line of MEL code to get the id "commandButton1" (it is similar way in python):

string $currentCmdBtn = `MGPicker -q -currentItem`;

 

To get other certain picker item ids, still it is a good idea to avoid id hard-coding since the id are not allowed to be duplicated, if you copy the item and paste it into other picker files, the id will probably not be the same as the original, which may cause a failure of the scripts used in the picker.

 

To make the script more portable, try avoiding hard-code the id by using the name property.

For each picker item, a name can be set up in the attribute editor, name value can be duplicated, so even if you copy the button and paste it to other pickers, the name property remains unchanged. so you can use the name properties as markers, to get ids from them. Say you have named a button "targetButton", in any place of picker you can use this line of MEL code to get its id (it is similar way in python):

string $IDs[] =`MGPickerView -q -getIdFromName "targetButton"`;

This will return all the picker items that have the name "targetButton";

If you only have one named "targetButton", it will still return a string array containing one element, you can use $IDs[0] as the button id.

 

How to iterate through all the picker items in current picker?

Say you wanna list all the select-buttons in the current picker  (it is similar way in python):

string $selectButtons[] = `MGPickerView -q -list "selectButton"`;

To list all the picker items regardless of the type:

string $selectButtons[] = `MGPickerView -q -list ""`;

To list all the links within the current picker regardless of the type:

string $allLinks[] = `MGPickerView -q -listLinks ""`;

Refer to MGPickerView command to know more.

 

How to query / edit things in a picker view, if it is not currently activated?

From 1.6, you could access through:

string $currentViewId = `MGPicker -q -currentPickerView`;        //This currentPickerView only be set during the execution of picker scripts, such as picker load command, picker mouse enter command.

// Then, you could use this command to query / edit things:    MGPickerView -q/-e ..$currentViewId;

 

Home Previous Next