in Installation by

I am using the link tool in the picker to display and hide the picker controls.

The problem is what I want is :

attr = 0 controls  HIDDEN

attr - 1 most controls DISPLAYED

attr = 2 the controls displayed at level 1 still displayed plus extra controls

But id I link to the attr at value 1 when I go to value 2 to display the extra controls all the my controls linked to 1 are hidden. 

Is there any way round this . 

Can I link the same controls to 1 and 2 ? Should I make duplicate buttons to link to 2 ?

1 Answer

0 votes
by
 
Best answer

This is an interesting case. 

Technically, I'm sure this is possible, but the link tool UX happens to make this difficult, the new relationship panel also does not give this a chance neither.

It will all work if the actual attribute is an enum attribute, where the link tool will allow you to make multiple selections for the target values, but not for integer or float attributes.
I will improve this, to at least allow the user to input multiple target values in the relationship panel in v2.

If the attribute has to be an integer value, for the moment you will have to use MGPicker API.

These are the ways to go:

  1. Set the attribute value to 1, select the target attribute button, go to the attribute editor,  copy its ID from the top row, and replace the green text in the code below.
  2. Select the mid-level controls that are supposed to show at values 1 and 2, and run the codes in the script editor.
  3. from maya import cmds
    
    def link_at_target_values(target_attr_btn, target_values):
        sel = cmds.MGPickerView(q=True, sel=True) or []
        if target_attr_btn in sel:
            sel = sel.remove(target_attr_btn)
        error_msg = "Please select picker items to link to the attribute button at the target values."
        if not sel:
            print(error_msg)
            return
           
        if cmds.MGPickerItem(target_attr_btn, q=True, type=True) != "attributeButton":
            print("The target_attr_btn is not actually a attribute button")
            return
           
        for btn in sel:
            cmds.MGPickerLink(s=btn, t=target_attr_btn, targetValues=target_values)
           
    
    # now select the mid-level buttons you want to show both at value 1 or 2,
    # and copy the target attribute button id from attribute editor:
    link_at_target_values("attributeButton2", "1,2")    # replace the attributeButton2 with the actual attributton ID.

     

  4. You will see the links with correct target values are created.
  5. Switch the attribute button value to 2, and use the link tool to link extra controls at that value.

Categories

...