View Full Version : Changing color when select different component
06 June 2008, 05:40 PM
I wonder If we could shade object in different color when selected different component
For example when I choose vertex. The object is shaded in blue and selected vertices is yellow
In face mode, the object is shade green and selected face is red
I guess there is some macro run in background and "listen" to what we do,
THanks for any help
06 June 2008, 06:43 PM
Here's a snippet.
-- remove any pre-existing callback here
-- will hold the object we're messing with
global orgObj = undefined
global orgMat = undefined
-- some materials pre-defined so we don't create new instances all the time
global redMat = Standard diffuse:(color 128 0 0)
global greenMat = Standard diffuse:(color 0 128 0)
global blueMat = Standard diffuse:(color 0 0 128)
global greyMat = Standard diffuse:(color 128 128 128)
-- the function that does it all
-- it gets the current and previous sub-object level from a callback, see below.
fn colorBySOLevel SOLevels = (
local newSOLevel = SOLevels
local oldSOLevel = SOLevels
-- get the currently selected object
local sel = getCurrentSelection()
-- if the old SOLevel was zero (no sub-object level)
if (oldSOLevel == 0) then (
-- then store a reference to this object, and to its original material
orgObj = sel
orgMat = sel.material
-- now assign it a new material based on the subObjectLevel.
sel.material = case newSOLevel of (
0: orgMat -- restore the original material if we're going out of SO mode.
1: greyMat -- vertices, typically
2: greenMat -- edges, typically
3: greenMat -- ditto, but in loop form
4: blueMat -- faces, typically
5: redMat -- elements, typically
default: greyMat -- anything else (just in case)
-- this callback tracks modifier panel SO level changes
-- and feeds the function the old and new SO levels.
callbacks.addScript #ModPanelSubObjectLevelChanged "colorBySOLevel (callbacks.notificationParam())" id:#test
-- while we use this one to make sure that if you exit SO level 'uncleanly'..
-- ( for example, by switching to the Create panel directly )
-- ..the original material will still get restored.
-- It does check if the object is still valid, in case the node was deleted or so.
callbacks.addScript #modPanelObjPostChange "if (isValidNode orgObj) then ( orgObj.material = orgMat )" id:#test
06 June 2008, 06:51 PM
as for actual selections... I'm not too sure if/where one might change that. I know that the SO selection color is in Customize > Customize User Interface -> Elements: Geometry \/ -> SubSelection |^|.. but script access to it, short of changing the .clr and then loading it in? hmm.
06 June 2008, 02:17 AM
Thanks for your hint, I will look into this snippet :thumbsup:
06 June 2008, 02:17 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.