Notifications
Clear all

[Closed] Toggling viewport materials display

I´m trying to figure out how to toggle the viewport materials display. Basicly I want to be able to toggle between shaded with maps and shaded without maps.

I´m getting a little more familiar with the Maxscript reference and found the Viewport Shading Settings.
http://docs.autodesk.com/3DSMAX/14/ENU/MAXScript%20Help%202012/

vss = maxops.getViewportShadingSettings()
<IObject:ViewportShadingSettings>
showInterfaces vss
  Interface: ViewportBasicSettings
   Properties:
    .ActivateViewportShading : bool : Read|Write
    .ShadingQuality : enum : Read|Write
       ShadingQuality enums: {#Good|#Best}
    .ShadowsActive : bool : Read|Write
    .TonemappingActive : bool : Read|Write
   Methods:
   Actions:
  Interface: ViewportGISettings
   Properties:
    .AmbientOcclusionMode : enum : Read|Write
       AmbientOcclusionMode enums: {#AOOff|#AOOnly|#AOComposite}
    .AmbientOcclusionQuality : enum : Read|Write
       AmbientOcclusionQuality enums: {#Low|#Medium|#High}
    .AmbientOcclusionRadius : float : Read|Write
    .AmbientOcclusionStrength : float : Read|Write
    .IndirectLightingMode : enum : Read|Write
       IndirectLightingMode enums: {#ILOff|#ILOnly|#ILAOComposite}
    .IndirectLightingQuality : enum : Read|Write
       IndirectLightingQuality enums: {#Low|#Medium|#High}
    .IndirectLightingRadius : float : Read|Write
    .IndirectLightingMultiplier : float : Read|Write
    .DepthOfFieldActive : bool : Read|Write
    .DepthOfFieldNearPlane : float : Read|Write
    .DepthOfFieldFarPlane : float : Read|Write
    .DepthOfFieldFocusPlane : float : Read|Write
   Methods:
   Actions:
  Interface: ViewportShadowSettings
   Properties:
    .ShadowMode : enum : Read|Write
       ShadowMode enums: {#Hard|#Soft}
   Methods:
   Actions:
OK

Appears to be nothing there…

Also found:
http://docs.autodesk.com/3DSMAX/14/ENU/MAXScript%20Help%202012/

But it’s a function that you run on a particular object, which isn’t what I’m after.

19 Replies
1 Reply
(@denist)
Joined: 10 months ago

Posts: 0

i guess you talk about display option – show all shaded with material and without.
it’s:

displayColor.shaded = #material
displayColor.shaded = #object 

Did you try running the commands from the viewport drop-down and getting the MacroRecorder output?

actionMan.executeAction 0 "63547"  -- Views: Viewport Materials Display as Realistic with Maps
actionMan.executeAction 0 "63546"  -- Views: Viewport Materials Display as Realistic
actionMan.executeAction 0 "63545"  -- Views: Viewport Materials Display as Shaded with Maps
actionMan.executeAction 0 "63544"  -- Views: Viewport Materials Display as Shaded

-Eric

I did. But what am I supposed to do with that? Run a macro inside another macro? Even if that is possible I would prefer to know what said macro consists of.

1 Reply
(@polytools3d)
Joined: 10 months ago

Posts: 0

Sometimes, the only way to do certain things in MXS is by running a Macro, and if it happen that you are creating a Macro too, then you would have to run a Macro from a Macro.

Not sure if that is the case of this specific task though.

Hello

You may use these snippets of code to build your script
I hope this will help



-- collect objects in scene what have materials assigned
obj = for obj in objects where obj.material != undefined collect obj

-- turn off
for o in obj do showTextureMap o.material o.material.diffuseMap off

-- turn on
for o in obj do showTextureMap o.material o.material.diffuseMap on


-- Turn on Shaded mode 
-- find the perspective viewport
for i=1 to viewport.numViews where (viewport.getType index:i) == #view_persp_user do
(
	
	local disp = NitrousGraphicsManager.GetActiveViewportSetting()
	-- Make Shaded view
	disp.ViewportViewSettingImpl.VisualStyleMode = #Shaded
	-- enable Edged faces view mode
	disp.ViewportViewSettingImpl.ShowEdgedFacesEnabled = true
)



-- Tunr on Realistic mode
-- find the perspective viewport
for i=1 to viewport.numViews where (viewport.getType index:i) == #view_persp_user do
(
	
	local disp = NitrousGraphicsManager.GetActiveViewportSetting()
	-- Make Shaded view
	disp.ViewportViewSettingImpl.VisualStyleMode = #Realistic 
	-- disable Edged faces view mode if you wish
	disp.ViewportViewSettingImpl.ShowEdgedFacesEnabled = false
)

That code gives me an error

-- collect objects in scene what have materials assigned
obj = for obj in objects where obj.material != undefined collect obj

-- turn off
for o in obj do showTextureMap o.material o.material.diffuseMap off
-- No "map" function for undefined

Try the code bellow instead and see if you get same error again


-- turn material visibility on 
for o in objects where o.material != undefined do showTextureMap o.material on

-- turn material visibility off
for o in objects where o.material != undefined do showTextureMap o.material off


1 Reply
(@deadlynightshade)
Joined: 10 months ago

Posts: 0

Works like a charm!
Do you have an example of a universal/generic toggle as well? I would like to be able to toggle this setting on/off for ALL materials without having to query the status of all objects in the scene, or in other words: I do NOT want a script that simply inverts the material -value. I want them all to be off the first time the script runs, all of the on the second time, all of them off the third, etc. In Maya, this can be done with an option variable or a global variable (which is saved between instances of Maya) – like this:

{
	global int $toggle; // variable declaration

	if ($toggle)
	{	
		// code which turns off material display
		$toggle= false;
	} else {
		// code which turns on material display
		$toggle= true;
	}
}

I would like something similiar for MAXScript.

If I have understood you correctly you want to do kind of one button switch.
In this case is possible to make something like this


fn toggleTextures = (
	-- initialize toggle variable
	if toggle == undefined then global toggle = false

	-- if toggle is true turn extures on
	-- if toggle is false turn textures off
	for o in objects where o.material != undefined do showTextureMap o.material toggle

	-- convert bulean value
	toggle = not toggle
)

toggleTextures()

 

macroScript NS_materialToggle
Category:"Nightshade"
toolTip:"Viewport Material Display Toggle"
buttontext:"Viewport Material Display Toggle"
(
	-- Create toggle var
	if toggle == undefined then global toggle = false
    
    -- Get objects in the scene which have a material
    obj = for obj in objects where obj.material != undefined collect obj

	-- Turn on/off
    if toggle == false then
        for o in objects where o.material != undefined do showTextureMap o.material on
    else
        for o in objects where o.material != undefined do showTextureMap o.material toggle

	-- Invert boolean
	toggle = not toggle
)

– Unable to convert: undefined to type: Boolean

So appearently, the toggle variable is not made into a global variable?

Also tried running it directly in the listener:

fn toggleTextures = (
	-- Create toggle var
	if toggle == undefined then global toggle = false

	-- Get objects in the scene which have a material
	obj = for obj in objects where obj.material != undefined collect obj

	-- Turn on/off
	if toggle == false then
		for o in objects where o.material != undefined do showTextureMap o.material on
	else
		for o in objects where o.material != undefined do showTextureMap o.material toggle

	-- Invert boolean
	toggle = not toggle
)
toggleTextures()

– Type error: Call needs function or class, got: undefined

You over complicated a bit
this is all you need to turn on/off materials in viewport


macroScript NS_materialToggle
Category:"Nightshade"
toolTip:"Viewport Material Display Toggle"
buttontext:"Viewport Material Display Toggle"
(
   if toggle == undefined then global toggle = false
   for o in objects where o.material != undefined do showTextureMap o.material toggle
   toggle = not toggle
)

That is indeed much more simple.
However, I get the same error message as before:
– Unable to convert: undefined to type: Boolean

Page 1 / 2