Home  Previous Next

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

To get the id of 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 similiar way in python):

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

 

To get other certain picker item ids, still it is 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 the same as the original, which may cause a failure of the scripts used in 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 attribute editor, name value can be duplicated, so even if you copy the button and paste it to other picker, 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 to "targetButton", in any place of picker you can use this line of mel code to get its id (it is similiar way in python):

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

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

If you only has one that named "targetButton", it will still return a string array contains 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 current picker  (it is similiar 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 current picker regardless of the type:

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

Refer to MGPicker 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 though:

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