Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
[MaxScript] LayerManager Add-Ons
/***********************************************************************************
NAME/ em_LMAddons
AUTHORS/ Mhamed Elmezoued
VERSION/ 1.0
DESCRIPTION/
Add-ons for the layer manager.
- Delete unused layer(s) : allows, as its name suggests deleting unused (or empty) layers
- Delete Hierarchy : delete the selected layers with all their children (layers or objects)
INSTALL/
Drag&drop the mcr into your viewport and customise your Quad, add them into "LayerExplorer Quad" or "SceneExplorer Quad", you will find them in the category "Scene Explorer".
LASTUPDATE/ 24.06.2016
CHANGELOG/
KNOW BUGS AND ISSUES/
Copyright (c) 2016 Mhamed Elmezoued (mhamed.e@gmail.com)
***********************************************************************************/
macroScript SEDeleteHierarchy
category:"Scene Explorer"
internalCategory: "Scene Explorer" --LOC_NOTES: do not localize this
toolTip: "Delete Hierarchy" --LOC_NOTES: localize this
ButtonText: "Delete Hierarchy" --LOC_NOTES: localize this
(
fn IsLayer item = ( classof item == Base_LayerBase_Layer)
on isVisible do
(
local sceneExplorerInstance = SceneExplorerManager.GetActiveExplorer()
return ( sceneExplorerInstance != undefined )
)
on isEnabled do
(
local sceneExplorerInstance = SceneExplorerManager.GetActiveExplorer()
if (sceneExplorerInstance == undefined) then return false
local selectedItems = sceneExplorerInstance.SelectedItems()
local hasDeletableLayers = false
local hasNonDeletableLayers = false
local hasNodes = false
for item in selectedItems while not hasNonDeletableLayers do
(
if (IsLayer item) then
(
if item.canDelete() then
hasDeletableLayers = true
else
hasNonDeletableLayers = false
)
else
hasNodes = false
)
return true
)
on execute do
(
local sceneExplorerInstance = SceneExplorerManager.GetActiveExplorer()
local selectedNodes = #()
local selectedLayers = #()
local selectedItems = sceneExplorerInstance.SelectedItems()
sceneExplorerInstance.SelectChildren()
local selectedChildren = sceneExplorerInstance.SelectedItems()
join selectedItems selectedChildren
for item in selectedItems do
(
if (IsLayer item) then
(
append selectedLayers item
)
else
(
append selectedNodes item
)
)
if (selectedNodes.Count > 0) then
(
delete selectedNodes
)
for layer in selectedLayers do
(
LayerManager.deleteLayerHierarchy layer.name forceDelete:true
LayerManager.deleteLayerByName layer.name
)
)
)
macroScript SEDeleteUnuse
category:"Scene Explorer"
internalCategory: "Scene Explorer"
toolTip: "Delete Unused Layer(s)"
ButtonText: "Delete Unused Layer(s)"
(
on isVisible do
(
local sceneExplorerInstance = SceneExplorerManager.GetActiveExplorer()
return ( sceneExplorerInstance != undefined )
)
on isEnabled do
(
local sceneExplorerInstance = SceneExplorerManager.GetActiveExplorer()
if (sceneExplorerInstance == undefined) then return false
return true
)
on execute do
(
for i = (layerManager.count - 1) to 1 by -1 do (
layername = (LayerManager.getLayer i).name as string
if (not LayerManager.doesLayerHierarchyContainNodes layername) then
(
LayerManager.deleteLayerByName layername
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment