Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to add -dragCallback and -dropCallbacks to buttons on Shelf?

6 REPLIES 6
Reply
Message 1 of 7
absoluteKelvin
282 Views, 6 Replies

How to add -dragCallback and -dropCallbacks to buttons on Shelf?

is there a way to add callbacks for shelf buttons? I read the documentation that it is suppose to support them. but when i added my own custom callback. Maya will auto delete them once maya session is closed and reopen.

 

anyway around this issue?

https://www.artstation.com/kelvintam
6 REPLIES 6
Message 2 of 7

Maya 2022 is the last version I did any real shelf coding in, but shelf buttons have been historically awful at preserving the data you assign to them, for example, even in 2022, if you simply copy a shelf button to the same shelf, or drag it onto a different shelf you lose any -docTag or -annotation applied to it, so it wouldn't surprise me that any drag/drop args/flags also suffer from this lack of persistant attachment.

I suspect the issue is that, because shelves are saved and loaded as MEL, the function that parses them to write the files out doesn't account for every flag supported by the command itself, so when the buttons move or are later reloaded, some data is lost.

I implemented a neat system that tracked shelfbuttons and stored extra funcitonality via the docTag, but it just didn't work in practice due to this issue. I had to encode the same data into the actual shelfButton command as a comment (as command strings are obviously fully preserved/restored) and then write an additional startup function to parse the comments and restore the functionality every time Maya launches, so maybe something like this could also work for you here.

Message 3 of 7

interesting, that might be an option. Im currently writing a collapsible separator for the shelf, it is able to hide buttons when activated. However it is not dynamic, if user rearranged it over another separator it stops working correctly. So the callback function was suppose to get the new position of the drop control and feed it back to the command.

 

https://www.artstation.com/kelvintam
Message 4 of 7

That's a really good idea, and something the Maya shelves should definitely already have as a feature!

However, I can already appreciate how tricky and complicated this could be to maintain and keep track of... 🤔

Message 5 of 7

Thanks. Yes it would be nice if Maya devs add this to vanilla maya. I just need to keep digging to see how maya keeps track of buttons position internally and hack it. It is very tricky indeed.
https://www.artstation.com/kelvintam
Message 6 of 7

I liked this idea so much I knocked up a quick and simple implementation of my own, apologies, I hope you don't mind me stealing your idea 😅

 

I figured it was a lot of work to try to track anything at all, so I reasoned "why don't I just make the separator button simply hide or show anything to the right of it, up to the next detected separator, wherever it happens to be when clicked". This turned out to be really simple to implement.

 

Whenever a separator is clicked it runs a function that queries every item on the current shelf, iterates over this list, and as soon as it finds "itself" (the clicked button) it starts setting the -manage flag of every subsequent shelfButton to True/False, depending on the "state" of the separator (which I simply use its assigned icon to determine) - until it hits another separator and then it stops the iteration.

 

I don't bother tracking or storing anything and it seems to work pretty well. The only "downside" is that if the user collapses a load of buttons and THEN drags the collapsed separator elsewhere, it doesn't actually "take" the "collapsed" icons with it. I don't know if you want your implementation to do this, but this seemed like a very minor issue in my opinion, as users wouldn't expect to be able to do that with a regular collapsible layout, and the lack of that functionality isn't really detrimental to the core behaviour or usefulness of the tool.

 

As a "solution" to the problem of users accidentally leaving icons hidden after moving a separator, I've just added a feature to the trigger function, whereby if the [Alt] key is held, it expands ALL separators on the shelf and shows all unmanaged buttons, so they can "reveal all" easily at any time if they mess up or want to "reset".

Message 7 of 7

Im glad you like this idea. I think my code is similar to yours in the general sense, I used

 

string $img = `shelfButton -q -i1 $shelfButton[$index]` //query the image used
if($img == "openBar.png"){
   shelfButton -edit -i1 "closeBar.png" $shelfButtons[$index];
   //do the -manage ....
}

 

Yes I think that it's reasonable not to expect collapsed buttons to move with along with the separator. Its adding too much complexity to the code IMO.

 

Great idea about using ALT key to expand all separators.👍

 

https://www.artstation.com/kelvintam

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report