/// <summary> /// Hides / Unhides all IILayer objects. /// </summary> public static void HideUnhideAll() { Boolean isHidden = false; IILayerManager LayerManager = GlobalInterface.Instance.COREInterface13.LayerManager; for (int i = 0; i < LayerManager.LayerCount; i++) { IILayer layer = LayerManager.GetLayer(i); if (!layer.IsHidden) { isHidden = true; } } for (int i = 0; i < LayerManager.LayerCount; i++) { IILayer layer = LayerManager.GetLayer(i); #if Max2013 || Max2014 layer.IsHidden = isHidden; #endif #if Max2015 layer.Hide(isHidden, false); #endif } MaxUI.RedrawViewportsNow(); }
public override void PutMaxValue(BaseTreeNode treeNode, Object newValue) { ObjectTreeNode objectTreeNode = treeNode as ObjectTreeNode; if (objectTreeNode != null) { IINode maxNode = MaxAnimatable.GetAnimByHandle(objectTreeNode.Handle) as IINode; if (maxNode != null) { maxNode.Hide(!(Boolean)newValue); } } LayerTreeNode layerTreeNode = treeNode as LayerTreeNode; if (layerTreeNode != null) { IILayer maxLayer = MaxAnimatable.GetAnimByHandle(layerTreeNode.Handle) as IILayer; #if Max2013 || Max2014 if (maxLayer != null) { maxLayer.IsHidden = !(Boolean)newValue; } #endif #if Max2015 if (maxLayer != null) { maxLayer.Hide(!(Boolean)newValue, false); } #endif } }
//TODO: // Perhaps move this to a new class / node control. It's pretty huge. // Use MaxLayers static class to manipulate max objects instead of in code here. /// <summary> /// Isolate selected TreeNodes in Nested Layer Manager. /// Any TreeNode that is not isolated is disabled, and the respective node hidden in Max. /// </summary> /// <param name="sender">An NLMCheckButton that contains a checked property.</param> /// <param name="e">NLM Button Event Args, that contain a pointer to the listview.</param> public static void onIsolateSelection(Object sender, ClickEventArgs e) { // If the sender is not an NLMCheckButton, the request has come from somewhere else (right click or shortcut). // For this reason, change the check state of the button UI which will raise this event again. if (!(sender is NlmCheckButton)) { e.ListView.ButtonPanelLeft.IsolateSelectedButton.Checked = !e.ListView.ButtonPanelLeft.IsolateSelectedButton.Checked; return; } NlmTreeListView listView = e.ListView; NlmCheckButton button = sender as NlmCheckButton; // Pause UI from refreshing. try { listView.BeginUpdate(); // Isolate selected if button checked. if (button.Checked) { // This method has some serious processing going on, so hashsets are used to maximise performance. // Calculate all enabled nodes and disabled nodes. HashSet <BaseTreeNode> enabledNodes = new HashSet <BaseTreeNode>(listView.NodeControl.Query.SelectionAndAllChildNodes); HashSet <BaseTreeNode> disabledNodes = new HashSet <BaseTreeNode>(listView.NodeControl.Query.AllNodes.Where(x => !enabledNodes.Contains(x))); // Disable disabled nodes. listView.DisableObjects(disabledNodes); // Now we need to work out what maxNodes and layers to temporarily hide. // Firstly, get the highest selected objects. IEnumerable <ObjectTreeNode> selectedNodes = listView.NodeControl.Query.SelectedAncestors .Where(x => (x is ObjectTreeNode)).Cast <ObjectTreeNode>(); HashSet <IILayer> onLayers = new HashSet <IILayer>(); // If objects are selected, we need to ensure that the layer is not hidden. // If any objects are selected, append the layer to the onLayers hashset. foreach (ObjectTreeNode objectTreeNode in selectedNodes) { IINode maxNode = MaxAnimatable.GetAnimByHandle(objectTreeNode.Handle) as IINode; if (maxNode == null) { continue; } IILayer layer = MaxLayers.GetLayer(maxNode); if (!onLayers.Contains(layer)) { onLayers.Add(layer); } } // Ensure that the layer is on so that objects are visible. // The layer is only turned on if an object is selected, and no ancestor is selected. // For any object that is not selected, the object needs to be hidden. foreach (IILayer layer in onLayers) { if (layer.IsHidden) { #if Max2013 || Max2014 layer.IsHidden = false; #endif #if Max2015 layer.Hide(false, false); #endif } foreach (IINode maxNode in MaxLayers.GetChildNodes(layer)) { UIntPtr maxNodeHandle = MaxAnimatable.GetHandleByAnim(maxNode); if (!selectedNodes.Any(x => (x).Handle == maxNodeHandle) && !maxNode.IsObjectHidden) { listView.DisabledHandles.Add(maxNodeHandle); maxNode.Hide(true); } } } // Loop through all layers that should be turned off. // If the layer should be hidden (because it is not in onLayers or in enabledLayers), hide it. IEnumerable <LayerTreeNode> enabledLayers = enabledNodes.Where(x => (x is LayerTreeNode)).Cast <LayerTreeNode>(); IEnumerable <IILayer> offLayers = MaxLayers.Layers.Where(x => !onLayers.Contains(x)); foreach (IILayer layer in offLayers) { UIntPtr layerHandle = MaxAnimatable.GetHandleByAnim(layer); if (!layer.IsHidden && !enabledLayers.Any(x => (x).Handle == layerHandle)) { #if Max2013 || Max2014 layer.IsHidden = true; #endif #if Max2015 layer.Hide(true, false); #endif listView.DisabledHandles.Add(layerHandle); } } } // Remove isolation and restore state if unchecked. else { // Enable all objects. listView.EnableObjects(listView.DisabledObjects); // Turn on all handles that were turned off. foreach (UIntPtr handle in listView.DisabledHandles) { IAnimatable maxAnim = MaxAnimatable.GetAnimByHandle(handle); IILayer maxLayer = maxAnim as IILayer; if (maxLayer != null) { #if Max2013 || Max2014 maxLayer.IsHidden = false; #endif #if Max2015 maxLayer.Hide(false, false); #endif continue; } IINode maxNode = maxAnim as IINode; if (maxNode != null) { maxNode.Hide(false); continue; } } // Clear list of handles. listView.DisabledHandles.Clear(); } } catch { throw new Exception(); } finally { listView.EndUpdate(); } MaxUI.RedrawViewportsNow(); }