Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

How do I save custom viewport gradient color themes for easy shelf button switching? (MEL script needed)

How do I save custom viewport gradient color themes for easy shelf button switching? (MEL script needed)

Meliko
Participant Participant
1,338 Views
6 Replies
Message 1 of 7

How do I save custom viewport gradient color themes for easy shelf button switching? (MEL script needed)

Meliko
Participant
Participant

Hi,

I want to create preset color gradients for my Maya Viewport that I can click and change from my shelf instead of going into Windows/Settings-Preferences/ColorSettings every time I want to change the viewport gradient colors.

The closest I found after searching was this post in the forum that had an awesome MEL script that allowed for solid color viewport presets as shelf buttons.

How do I register the color of the viewport in the shelf?

But I need the MEL script that would allow me to input the RGB 0-10 values for TOP and BOTTOM Gradient colors and keep them as shelf button presets?

Any help would be greatly appreciated!

Mel

Accepted solutions (1)
1,339 Views
6 Replies
Replies (6)
Message 2 of 7

amaterasu-qbb
Collaborator
Collaborator
Hi! @Meliko .

I thought this was closer to your question so I'm suggesting it. I hope it will be useful for you.
 
Also, I'm proposing an idea to make it possible to change this in real time, so please vote if you'd like.

Best,
Message 3 of 7

Meliko
Participant
Participant

Hi @amaterasu-qbb,

Thanks for the reply.  In my post, I actually linked to your post about BG colors as shelf buttons.  It's a good solution that I'll use for quickly changing BG colors with shelf buttons.  I'm hoping there's a way to save Gradient BG themes as shelf buttons also.

I like your idea of real time color changes in viewport like Blender.

Cheers

Message 4 of 7

amaterasu-qbb
Collaborator
Collaborator

Hi! @Meliko .

I just saw that you put the link to my question in your original post. I apologize for that. Unfortunately, I can't solve this problem, but I've summarized everything I've researched.

 

This is the command when you change Background from 3D View in Color Setting.

 

updateRGBColor background;
updateColorPrefUI;
from maya.plugin.evaluator.cache_ui import cache_ui_colour_preferences_update
cache_ui_colour_preferences_update()

// I tried both with different colors and the same command returned.

updateRGBColor background;
updateColorPrefUI;
from maya.plugin.evaluator.cache_ui import cache_ui_colour_preferences_update
cache_ui_colour_preferences_update()

 

 

This is the command when changing Gradient Top from 3D View of Color Setting.

 

// Result: scriptEditorPanel1Window|scriptEditorPanel1|formLayout112|formLayout114|paneLayout2|cmdScrollFieldReporter1
updateRGBColor backgroundTop;
updateColorPrefUI;
from maya.plugin.evaluator.cache_ui import cache_ui_colour_preferences_update
cache_ui_colour_preferences_update()

// I tried both with different colors and the same command returned.

// Result: scriptEditorPanel1Window|scriptEditorPanel1|formLayout112|formLayout114|paneLayout2|cmdScrollFieldReporter1
updateRGBColor backgroundTop;
updateColorPrefUI;
from maya.plugin.evaluator.cache_ui import cache_ui_colour_preferences_update
cache_ui_colour_preferences_update()

 

 

This is the command when changing Gradient Bottom from 3D View of Color Setting.

 

// Result: scriptEditorPanel1Window|scriptEditorPanel1|formLayout112|formLayout114|paneLayout2|cmdScrollFieldReporter1
updateRGBColor backgroundBottom;
updateColorPrefUI;
from maya.plugin.evaluator.cache_ui import cache_ui_colour_preferences_update
cache_ui_colour_preferences_update()

// I tried both with different colors and the same command returned.

// Result: scriptEditorPanel1Window|scriptEditorPanel1|formLayout112|formLayout114|paneLayout2|cmdScrollFieldReporter1
updateRGBColor backgroundBottom;
updateColorPrefUI;
from maya.plugin.evaluator.cache_ui import cache_ui_colour_preferences_update
cache_ui_colour_preferences_update()

 

 

You can see that there are commands that are common to each.

  1. from maya.plugin.evaluator.cache_ui import cache_ui_colour_preferences_update
  2. cache_ui_colour_preferences_update()
  3. updateRGBColor

Checking these with the whatIs command is as follows.

 

from maya.plugin.evaluator.cache_ui import cache_ui_colour_preferences_update
// Result: Unknown
cache_ui_colour_preferences_update()
// Result: Unknown
updateRGBColor
// Result: Mel procedure found in: C:/Program Files/Autodesk/Maya2023/scripts/others/colorPrefWnd.mel
// updateRGBColor command
global proc updateRGBColor (string $colorName) {
	string $widgetName = rgbSliderWidget($colorName);
	float $col[];
	$col=`colorSliderGrp -q -rgb $widgetName`;
	float $alpha[]=`colorSliderGrp -q -alphaValue $widgetName`;
	displayRGBColor $colorName $col[0] $col[1] $col[2] $alpha[0];
		
	// If the User Defined Color Palette window is up, update it
	// We don't check what colour is being updated here because
	// the checking is slower than actually doing the work
	//
	global string $gObjColorPalette;
	if (`palettePort -exists $gObjColorPalette`) {
		initObjColorPalette();
	}
}

 

 

It might be a good idea to ask the same question on the Maya Programming forums.

Also, I think this will involve using an API that does more complex processing than MEL, so it may be difficult to get an answer.

 

Best,

 

Message 5 of 7

Meliko
Participant
Participant

Hi @amaterasu-qbb 

Wow. Thanks very much for getting this code!

I echoed commands in script editor but there was nothing when I changed colors in the Color Settings pref panel.  How did you get this code?

I will play around with this and see if I can affect the gradient colors but since I'm not a coder, I don't have high hopes.  Your suggestion to ask in the programmers forum is a good one.

Thanks for taking the time to dive into this.  Much appreciated!

0 Likes
Message 6 of 7

brian.kramer
Alumni
Alumni
Accepted solution

Hi Meliko,

 

If I understand correctly you want want to change the viewport background colour using shelf buttons?

 

Here are 4 little MEL scripts snippets that I think may help:

 

// Solid 1
displayPref -displayGradient false;
displayRGBColor "background" 0.7 0.7 0.6;

 

// Solid 2
displayPref -displayGradient false;
displayRGBColor "background" 0.6 0.7 0.7;

 

// Gradient 1
displayPref -displayGradient true;
displayRGBColor "backgroundTop" 0.4 0.4 0.5;
displayRGBColor "backgroundBottom" 0.7 0.8 0.7;

 

// Gradient 2
displayPref -displayGradient true;
displayRGBColor "backgroundTop" 0.5 0.3 0.6;
displayRGBColor "backgroundBottom" 0.5 0.8 0.6;

 

Paste everything into the Script Editor then select each snippet one at a time. Drag each selection to your shelf.

You should wind up with 4 buttons on your shelf which will change the viewport background.

 

Hope this helps,

-Brian


Brian Kramer
Software Developer
Message 7 of 7

Meliko
Participant
Participant

Hi @brian.kramer 

THANK YOU!!  This was exactly what I wanted and it's working flawlessly now. 

Much appreciated!