Home Technical Talk
The BRAWL² Tournament Challenge has been announced!

It starts May 12, and ends Oct 17. Let's see what you got!

https://polycount.com/discussion/237047/the-brawl²-tournament

how to get what attribute is selected in channel box on right

Dav
Dav
Hi

I want to build my own toggle switch for lock selected and key slected or unlock , to do that i just simply want to click a button to toggle in shelf so that if i select any attribute of the object i should be able to lock or unlock just with a click rather than doing right cliock and lock selected..please help...

Replies

  • kodde
    Offline / Send Message
    kodde polycounter lvl 20
    I take it you are talking about Maya.

    Welcome to polycount btw. Did you try just dissecting the output in the script editor from doing it manually?
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 16
    string $sel[] = `ls -sl`;
    string $selectChannels[] = `channelBox  -q -selectedMainAttributes mainChannelBox`;
    if(`size $selectChannels`!=0 && `size $sel` != 0){
    for($thisObj in $sel){
        for ($thisChannel in $selectChannels){
            setAttr -lock (!`getAttr -l ($thisObj + "." + $thisChannel)`) ($thisObj + "." + $thisChannel);
        }
    
    }
    }
    else {
        warning("Please select an object and the channels you want to lock");
    }
    

    Just wrote this up , should toggle the current selected attribute to locked and unlocked. If you wanted to build something else the command your looking for is:

    channelBox -q -selectedMainAttributes mainChannelBox
  • Dav
    i understand and thats what i was looking for,

    also i believe its better to use "!" mark to make a check rather then using an if statement, that makes it easier to put the getAttr inside the setAttr

    just one more basic ques how does $thisChannel selects once channel at a time from $selectChannels ? is it what for loop is doing, coz its iterating. the the max in selection.
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 16
    Yeah the $thisChannel is a variable that is declared in a for in loop and basically loops through an array (in our case the objects selected so we can locked multiple attributes across multiple objects and the selected channels) assigning each index of the array to $thisChannel. Its basically a simpler version of the traditional for loop. I'm using the if statement to check to see if any objects are selected and if there is a channel selected.
Sign In or Register to comment.