Freebie - 3dsMax "Isolated Selected" Editor Scrip

Hi all

Just made this little script that hides everything else but the objects you have selected then allows you to bring everything back again. Inspired by the “Isolate Selected” feature in Max.

Some of you may have used the “Hide Unselected” option in Max which is similar but Isolate selected remembers the previous enabled/disabled state when you cancel it unlike “Unhide all”.

It basically remembers all mesh renderer enabled state, sets it to off for all unselected objects then when your done it sets it back to what it was originally (either off or on).

It’s my first Editor Script so use at own risk, feel free to update it.

Create an \Editor folder in your assets folder and drop this js file in there. When Unity compiles it you will have a new menu called Geoff :slight_smile:

// 	Isolate selected feature from 3DSMax
//
// 	all the scene objects mesh renderer enabled state is stored and restored on use.
//  Will not hide objects that dont have a mesh renderer like lights.
//  If you forget to cancel the Isolate and reload unity then you will have to re-enable the renderer's manually.
//
//  Geoff Coope (coope.geoff@gmail.com)
//  Version 0.01 Alpha 
//

static var sel_set;						// List of object names selected
static var allObjects;					// All scene objects that have a renderer
static var allObjectsState = new Array();		// List of enabled and disabled states


@MenuItem ("Geoff/Isolate/Isolate selected")
static function isolate () {
	var n = 0;
	
	// Create array of existing enabled states for all objects
	allObjects = GameObject.FindSceneObjectsOfType(typeof (Renderer));
	for (var i in allObjects){
		allObjectsState[n] = i.enabled;
		n++;
	}
		
	sel_set = Selection.GetFiltered(Renderer, SelectionMode.Editable);
	
	// Hide everything else but the selected objects
	  for (var o in allObjects)
      {
           // See if o.name exists in sel_set, if it doesent then hide it.
		   if(exists(sel_set, o.name)==false){
				o.enabled = false;
		   }
      }
	}		

	
@MenuItem ("Geoff/Isolate/Cancle Isolation")
static function CancleIsolation () {
	var n = 0;
	
	// Set enabled state back to what it was.
	  for (var o in allObjects)
      {
	   o.enabled = allObjectsState[n];
	   n++;
	  }

}	

static function exists(arr,obj) {
    //return (arr.indexOf(obj) != -1);
	var i;
for(i = 0; i < arr.Length; i++)
{
  if(arr[i].name == obj)
  {
	return true;
  }
} 
	return false;
}

:evil:

It would seem that creating an animation clip clears the remember object list in the editor which stops you cancelling the isolation.