Maya coding conundrums

Hi there, there are a few issues here that stumped me in Maya (over the last 6 months), and I didn’t get any answers from other places, I wonder if anybody can shed some light ? I am rebuilding UI and coding tools for my own benefit, to make Maya a more beautiful experience for a generalist.

  1. Is there a scriptjob that can detect when an error has been thrown to trigger getLastError. I would like to keep a little UI that is a one liner that tracks the last error in this way. (Rather than using catch for everything…) . ie. as issues crop up… I fix them one by one…

2.Is there any way/hack to intercept the right click menu on attributes in the AE, I read this is hard coded, but if there was a sneaky way around it I could stick in some extra functionality… That’s where we have (Set key, Create new expression, etc menu… ). This would work everywhere, so wouldn’t have to code custom attribute controls. Alternatively, if there was a way to detect what control (controlling what attribute) was under the mouse pointer, a script could operate in different ways… I suppose this can be read from the Channel box, but is there any way to read it from the Attribute Editor.

I have realised that I have a lot of questions - so Ill just leave it at those two for now, so not to bombard…

Many thanks for any enlightenment…

Alan.


If you are using Python you can override stderr and do with it what you want. As for the menus and the such <shrug>. I’m not enough of a Maya API guru to be able to answer that.

If you turn on “Echo All Commands” and watch the output in the Script Editor while you activate the Right-Click context menu in the AE, you can see what commands are called. Using the “whatIs” MEL command, you can find the .mel files containing the code.

You can copy and paste those .mel files into your own folder, as along as it is on the SCRIPT_PATH, and make modifications to it. When Maya launches it will find your modified version and ignore the version in the application folder.
You can then hack in your additions.

There is an old, but very good, thread on here for hacking into Maya’s context menus, lemme try to dig it up.

this thread may help you:

Hey thanks for that, yes I am aware of tracking the commands etc and I have sniffed around the .mel that creates the attribute editor etc but can’t seem to locate where this menu is generated. Nothing pops up in echo all commands… What you are referring to (I think) is context stuff that only works in the main panes, ie. the model editors…

The Attribute Editor is built from attributeControlGroups… so perhaps the code is buried in them…

Again if there was a way of detecting the actual control under the pointer, I could code a marking menu using a different hotkey to perform operations on the attribute, but that seems to be missing (from mel/python - I am not into the API).
Many thanks
A

ps what I am doing at the moment is using a control group that connects to SRT of selected object, and at least then I can go forth and code popUps or whatever I want for that.

Oh hey I forgot to query popupmenuarray… Maybe that will throw something up…

for #1, you can tap into the global exception handler. By default its stored in maya.utils._guiExceptHook, and you can replace it with your own function that does whatever you like. It’s pretty common to use a replacement function to log errors to email, a database, or some other storage/notification mechanism.

For #2: AETemplates are evil. The best you can manage is usually to get the names of the layouts created by the defaul mel AETemplates and then force-parent new stuff of your own under them. They are not native Python, which really stinks. However you can hack the AETemplate for a given type to add some hooks that you can call from Python. Typically the AETemplate block for a given node is named something like global proc AEYourThingHereUI(). You can add a call in there to call python(“your code here()”) and add your UI calls. It’s not ideal but it does work

[QUOTE=Theodox;30765]for #1, you can tap into the global exception handler. By default its stored in maya.utils._guiExceptHook, and you can replace it with your own function that does whatever you like. It’s pretty common to use a replacement function to log errors to email, a database, or some other storage/notification mechanism.

For #2: AETemplates are evil. The best you can manage is usually to get the names of the layouts created by the defaul mel AETemplates and then force-parent new stuff of your own under them. They are not native Python, which really stinks. However you can hack the AETemplate for a given type to add some hooks that you can call from Python. Typically the AETemplate block for a given node is named something like global proc AEYourThingHereUI(). You can add a call in there to call python(“your code here()”) and add your UI calls. It’s not ideal but it does work[/QUOTE]

Cool thanks for the feedback, I am stuck with MEL in terms of my current skillset… although in fairness there has been little that I have been unable to do with it. I had researched #2, putting callbacks on controls with AEtemplates so its easier to just create my own custom controls (SRT - the usuals) that have custom pop-ups, and connect to the selected object via scriptjob.

Thanks for the replies.
A

From a usability standpoint, also consider that adding your own popups to the attribute editor will block the standard attrControlGrp popup menus from displaying.

Also it looks like those popup menus are generated in Qt, unfortunately, so you can’t access them through MEL UI commands.

[QUOTE=capper;30775]From a usability standpoint, also consider that adding your own popups to the attribute editor will block the standard attrControlGrp popup menus from displaying.

Also it looks like those popup menus are generated in Qt, unfortunately, so you can’t access them through MEL UI commands.[/QUOTE]

Thanks a lot, I did a test with this and as long as you don’t interfere with the existing it’s fine… ie. put the popup on button=1 or use a modifier key, leaving the right click alone, then you can do both . . .