@roberto.gagliano wrote:
I could not yet figure out how to use your advanced script from Message #6
global VPT_BackgroundConfig
(
struct _vpt_backgroundconfig
(
modeID = 0,
buttID = 1,
solidColor = black,
fn preferenceCallback apply:on =
(
--format "modeID:% buttID:% color:%\n" modeID buttID solidColor
hwnd = DialogMonitorOPS.GetWindowHandle()
title = uiaccessor.GetWindowText hwnd
--format "hwnd:% text:%\n" hwnd title
if iskindof title String and matchpattern title pattern:"Viewport*Configuration" do
(
local TCM_SETCURFOCUS = 0x1330
local backgroundTabIndex = 1
children = uiaccessor.GetChildWindows hwnd
for child in children do
(
if ((uiaccessor.GetWindowClassName child) == "SysTabControl32") do
(
exit with (uiaccessor.SendMessage child TCM_SETCURFOCUS backgroundTabIndex 0)
)
)
if iskindof solidColor Color do backgroundColor = solidColor
back_hwnd = (windows.getChildHWND hwnd "Viewport Background")[1]
mode_hwnd = uiaccessor.GetFirstChildWindow back_hwnd
for k = 0 to 4 do
(
--format "vpmode % >> hwnd:%\t> %\n" k mode_hwnd (UIAccessor.GetWindowText mode_hwnd)
if modeID == k do
(
exit with (uiaccessor.PressButton mode_hwnd)
)
mode_hwnd = uiaccessor.GetNextWindow mode_hwnd
)
butt_hwnd = (windows.getChildHWND hwnd "OK")[1]
for k = 0 to 3 do
(
--format "button % >> hwnd:%\t> %\n" k butt_hwnd (UIAccessor.GetWindowText butt_hwnd)
if buttID == k do uiaccessor.PressButton butt_hwnd
butt_hwnd = uiaccessor.GetNextWindow butt_hwnd
)
uiaccessor.SendMessageID hwnd (if apply then #IDOK else #IDCANCEL)
)
true
),
fn setupBackground mode: action: color: =
(
if mode != unsupplied do modeID = case mode of
(
#gradient: 1
#custom: 2
#environment: 3
#file: 4
#default: 0
)
if action != unsupplied do buttID = case action of
(
#ok: 0
#cancel: 1
#active: 2
#all: 3
default: 1
)
if color != unsupplied do solidColor = color
local enabled = DialogMonitorOPS.Enabled
DialogMonitorOPS.RegisterNotification this.preferenceCallback id:#vptBackgroundConfig
DialogMonitorOPS.Enabled = true
max vptconfig
DialogMonitorOPS.unRegisterNotification id:#vptBackgroundConfig
DialogMonitorOPS.Enabled = enabled --false
ok
),
action_00 =
(
macroScript VPT_SUPER_BLACK
category:"with denisT"
buttonText:"SUPER BLACK"
toolTip:"View Background: SUPER BLACK (+SHIFT - ALL)"
autoUndoEnabled:off
silentErrors:off
(
local bcfg = undefined
local bgcol = black
local setts = undefined
fn is_enabled = isstruct (bcfg = ::VPT_BackgroundConfig)
fn v_settings = NitrousGraphicsManager.GetViewportSetting (if (i = viewport.activeViewportId) != undefined then i else -1)
on isEnabled do (is_enabled())
on isChecked do (setts = v_settings()) != undefined and
(
setts.UseEnvironmentBackgroundColorEnabled and (backgroundColor == bgcol)
)
on execute do if is_enabled() do
(
act = if keyboard.shiftPressed then #all else #active
bcfg.setupBackground mode:#environment action:act color:bgcol
)
)
),
action_01 =
(
macroScript VPT_BLACK
category:"with denisT"
buttonText:"BLACK"
toolTip:"View Background: BLACK (+SHIFT - ALL)"
autoUndoEnabled:off
silentErrors:off
(
local bcfg = undefined
local bgcol = (color 1 1 1)
local setts = undefined
fn is_enabled = isstruct (bcfg = ::VPT_BackgroundConfig)
fn v_settings = NitrousGraphicsManager.GetViewportSetting (if (i = viewport.activeViewportId) != undefined then i else -1)
on isEnabled do (is_enabled())
on isChecked do (setts = v_settings()) != undefined and
(
setts.UseEnvironmentBackgroundColorEnabled and (backgroundColor == bgcol)
)
on execute do if is_enabled() do
(
act = if keyboard.shiftPressed then #all else #active
bcfg.setupBackground mode:#environment action:act color:bgcol
)
)
),
action_02 =
(
macroScript VPT_DARK_GRAY
category:"with denisT"
buttonText:"DARK GRAY"
toolTip:"View Background: DARK GRAY (+SHIFT - ALL)"
autoUndoEnabled:off
silentErrors:off
(
local bcfg = undefined
local bgcol = (color 32 32 32)
local setts = undefined
fn is_enabled = isstruct (bcfg = ::VPT_BackgroundConfig)
fn v_settings = NitrousGraphicsManager.GetViewportSetting (if (i = viewport.activeViewportId) != undefined then i else -1)
on isEnabled do (is_enabled())
on isChecked do (setts = v_settings()) != undefined and
(
setts.UseEnvironmentBackgroundColorEnabled and (backgroundColor == bgcol)
)
on execute do if is_enabled() do
(
act = if keyboard.shiftPressed then #all else #active
bcfg.setupBackground mode:#environment action:act color:bgcol
)
)
),
action_03 =
(
macroScript VPT_CUSTOM
category:"with denisT"
buttonText:"CUSTOM"
toolTip:"View Background: CUSTOM (+SHIFT - ALL)"
autoUndoEnabled:off
silentErrors:off
(
local bcfg = undefined
fn is_enabled = isstruct (bcfg = ::VPT_BackgroundConfig)
on isEnabled do (is_enabled())
on execute do if is_enabled() do
(
act = if keyboard.shiftPressed then #all else #active
bcfg.setupBackground mode:#custom action:act
)
)
),
action_04 =
(
macroScript VPT_DEFAULT
category:"with denisT"
buttonText:"DEFAULT"
toolTip:"View Background: DEFAULT (+SHIFT - ALL)"
autoUndoEnabled:off
silentErrors:off
(
local bcfg = undefined
fn is_enabled = isstruct (bcfg = ::VPT_BackgroundConfig)
on isEnabled do (is_enabled())
on execute do if is_enabled() do
(
act = if keyboard.shiftPressed then #all else #active
bcfg.setupBackground mode:#default action:act
)
)
),
action_05 =
(
macroScript VPT_GRADIENT
category:"with denisT"
buttonText:"GRADIENT"
toolTip:"View Background: GRADIENT (+SHIFT - ALL)"
autoUndoEnabled:off
silentErrors:off
(
local bcfg = undefined
fn is_enabled = isstruct (bcfg = ::VPT_BackgroundConfig)
on isEnabled do (is_enabled())
on execute do if is_enabled() do
(
act = if keyboard.shiftPressed then #all else #active
bcfg.setupBackground mode:#gradient action:act
)
)
),
/* -- Solid Color Template
action_<index> =
(
macroScript VPT_<COLOR_NAME>
category:"with denisT"
buttonText:"<COLOR_NAME>"
toolTip:"View Background: <COLOR_NAME> (+SHIFT - ALL)"
autoUndoEnabled:off
silentErrors:off
(
local bcfg = undefined
local bgcol = color <R> <G> <B> -- or color built-in name
local setts = undefined
fn is_enabled = isstruct (bcfg = ::VPT_BackgroundConfig)
fn v_settings = NitrousGraphicsManager.GetViewportSetting (if (i = viewport.activeViewportId) != undefined then i else -1)
on isEnabled do (is_enabled())
on isChecked do (setts = v_settings()) != undefined and
(
setts.UseEnvironmentBackgroundColorEnabled and (backgroundColor == bgcol)
)
on execute do if is_enabled() do
(
act = if keyboard.shiftPressed then #all else #active
bcfg.setupBackground mode:#environment action:act color:bgcol
)
)
),
*/
on create do
(
callbacks.removeScripts id:#VPT_BackgroundConfig
callbacks.addScript #activeViewportChanged "updateToolbarButtons()" id:#VPT_BackgroundConfig
updateToolbarButtons()
)
)
VPT_BackgroundConfig = _vpt_backgroundconfig()
ok
)
save this code in any MS file with a name that makes sense to you... for example: "vpt_background.ms"
and put in any autoload max directory...
let's do it:
...\Program Files\Autodesk\3ds Max ***\stdplugs\stdscripts\vpt_background.ms
after restarting MAX you will see in Customize User Interface -> Toolbars -> Category: with denisT
and several View Background items - BLACK, CUSTOM, DARK GRAY etc...
Names correspond to the code's macro actions.
If you make macro buttons, clicking the button sets the background for the active viewport by default to the specified state, but if you click with SHIFT it will do for ALL viewports.
If you need to add your own color - just add a new action to the code... (see "Solid Color Template" in the code above)