ScriptSpot

Forum topic · General Scripting

Change UI colour when snap / lock is active ?

By asymptote · 2013-06-20

Description

Just a quick question to you guys, is it possible using Maxscript to change the colors of the UI when snap or lock is active ?

I'm simply looking for a way to give a better indication in the viewports that snap or lock is active.

For example changing the background colour to a different shade.

thanks.

Comments (23)

asymptote · 2013-06-21

"Do not blame me if your max say: "WTF is this. Bye,bye . Boom!" and crash. :)"

No worries, Max does that already ;)

Script is more than cool, I'll tweak the size and position of the boxes later, I can understand code and tweak variables that's about it :).

Thanks for you time ( although this was probably piss easy for you ;))

If you need any graphics work doing let me know :)

Thanks again.

barigazy · 2013-06-21

Thanks I will let you know. I works architectural and design stuffs for my job but scripting is only the hobby. Send U a PM. Very cool avatar :)

asymptote · 2013-06-21

No....my strength is coming up with ideas and suggesting them to people with the skills to implement them :)

I tried reading mxs help, but I fell asleep 3 lines in, it's like reading a bloody phone directory.

asymptote · 2013-06-21

Why are you programmers so reluctant to change ? Look...when Autokey key is active this happens.....

How hard would it be for a similar indication when snap / lock is active ?

And as far as destroying the UI, Autodesk are doing a good enough job of that already! :P

barigazy · 2013-06-21

No doubt that you're right. Also one more thing: I'm not programmer. These developers do not use mxs for that

asymptote · 2013-06-21

Developers? I wasn't aware AD had any ;)

;)

barigazy · 2013-06-21

Is this cool or what?

macroScript test category:"asymptote" buttonText:"SL_MODE" toolTip:"Snap | Lock State" --silentErrors:on
(
local isOpen = false
fn selLocked =
(
selectionlock = false
sel = selection as array
clearselection()
if selection.count != 0 then selectionlock = true else selectionlock = false
select sel
selectionlock
)
fn snap_lock_state =
(
local snapTxt = if snapMode.active then "ON" else "OFF"
local lockTxt = if not isCreatingObject() then (if selLocked() then "ON" else "OFF") else "OFF"
gw.hrect ( box2 2 3 85 15 ) (if snapTxt == "ON" then red else black)
gw.hrect ( box2 86 3 102 15 ) (if lockTxt == "ON" then red else black)
gw.htext [7, 3, 0] ("snapMode: "+snapTxt+" selectionLock: "+lockTxt) color:white
gw.enlargeUpdateRect #whole
gw.updateScreen()
redrawViews()
)
on execute do
(
if isOpen then (unregisterRedrawViewsCallback snap_lock_state ; redrawViews() ; isOpen = off)
else
(
unregisterRedrawViewsCallback snap_lock_state
registerRedrawViewsCallback snap_lock_state ; redrawViews()
isOpen = on
)
)
on isChecked return isOpen
)

or macroscript

barigazy · 2013-06-21

Plase this in MacroScripts folder
U can find it under category "asymptote".
Drag this buton someware in the toolbar.
Check it and look in the downleft corner of your viewport

Attachments

BTW

barigazy · 2013-06-21

Do not blame me if your max say: "WTF is this. Bye,bye . Boom!" and crash. :)
Anyway my suggestion is to use image that you posted before for your forum avatar to recognize you next time :)
Cheers!

Progress

asymptote · 2013-06-21

barigazy · 2013-06-21

Man you are funny.:)
You need to be patient and read mxs help.
I just wanted to give you a hint that code which do the checking will slow down max. You not want that for sure ... or what?

asymptote · 2013-06-21

I could use point 3 instead of colour if I knew what the hell I was doing :P

OK, what is the code / variable ? that listens for specific UI button presses, that may be a better place to start.

I don't want my tool to be a floater I want it to react to Max button press.

Is it possible for the viewport boundry ( yellow line) to be made bigger or as a gradient to indicate snap / lock ?

:)

barigazy · 2013-06-21

You want to know what you are doing? I can tell you: you are trying to destroy max interface with this and crash max? :)
If you not want floater then use one macrobutton to trigger callback or timer control. Try to post something to see your progress.

asymptote · 2013-06-20

lol no! I've never written a maxscript before, dot net? it's all gobbledygook to me. I've tried, I simply lack the knowledge. I'll stick to modeling and texturing.
I can live without it. :P

thanks anyway.

Here's an example of my scripting skills...two buttons one for on, and one for off,
I couldn't even figure out how to change the color from anything other than black.

On...

snapmode.active = on

CurrentColor = (GetUIColor 41*255) as color

if CurrentColor != color 0 0 0 then
(
SetUIColor 41 (color 0 0 0)
colorMan.repaintUI #repaintAll
)
else
(
SetUIColor 41 (color 131 131 131)
colorMan.repaintUI #repaintAll
)
)

Off...

snapmode.active = off

CurrentColor = (GetUIColor 41*255) as color

if CurrentColor != color 0 0 0 then
(
SetUIColor 41 (color 0 0 0)
colorMan.repaintUI #repaintAll
)
else
(
SetUIColor 41 (color 131 131 131)
colorMan.repaintUI #repaintAll
)
)

btw ...it doesn't flicker ;)

:)

barigazy · 2013-06-20

You can use point3 instead of color and you need to use also values 0-1 not 0-255.
So this is the way

SetUIColor 41 ([131,131,131]/255.0)

asymptote · 2013-06-20

Thanks barigazy but this is way beyond me, I'll have to turn this into a request script wanted instead.

asymptote · 2013-06-20

Thx barigazy, that's very helpful info, now i need to figure out how to combine the snap and the background toggle...this may take a while ;)

barigazy · 2013-06-20

The better idea is to use non-bordered dialog with two .net label controls which can indicates states of selection lock and snap mode. Mean back color of labels will be changed instead of viewport color whick can cause flickering because all UI components will be considered in color changing operation.
Anyway to trigger this operations you can use Timer control. That's my concept idea.

asymptote · 2013-06-20

I found this script by Nanne....

CurrentColor = (GetUIColor 41*255) as color

if CurrentColor != color 0 0 0 then
(
SetUIColor 41 (color 0 0 0)
colorMan.repaintUI #repaintAll
)
else
(
SetUIColor 41 (color 131 131 131)
colorMan.repaintUI #repaintAll
)
)

and this bit of code for snap....

snapmode.type = #3d

I can't find anything to toggle snap on or off, totally out of my depth here I've never scripted before :)

barigazy · 2013-06-20

for snaping you can use


snapMode.active = off
snapMode.active = on

And for selection lock this is the hack
(maxscript not provide better solution)

fn selLocked =
(
selectionlock = false
sel = selection as array
clearselection()
if selection.count != 0 then selectionlock = true else selectionlock = false
select sel
selectionlock
)
-- to lock
if not selLocked() do (max spacebar)
-- and unlock
if selLocked() do (max spacebar)

asymptote · 2013-06-20

So it is possible ?

Main reason is I'm not always looking at the snap and lock buttons I'm looking in the viewport, I always forget they are on.

I'm looking for some way to indicate more clearly in the viewport that a toggle is active.

Ideally that would be background colour.

barigazy · 2013-06-20

probably U will get flickering of the viewport if you do this.
I not know why you need that when lock and snap buttons are properly indicate lock or snap current state