Almost there with Render Layers isolate script but can't finish one thing

global string $isolate_original;
global int $remember;
 
// source isolate.mel; isolate;
 
global proc isolate(){
 
	global string $isolate_original;
	global int $remember;
	string $current = `editRenderLayerGlobals -q -currentRenderLayer`;
	string $default = "defaultRenderLayer";
	string $visPanel[] = `getPanel -vis`;
 
	if (size($visPanel)>0)
	{
	for ($panel in $visPanel)
		if (`match "^modelPanel" $panel`=="modelPanel")
		{
			if ($current!= $default) 
			{
 
				$mode=`modelEditor -q -viewSelected $panel`;
				enableIsolateSelect $panel (!`isolateSelect -q -state $panel`);
				editRenderLayerGlobals -currentRenderLayer $default;
				$isolate_original = $current;
			}
		else 
			{
				$mode=`modelEditor -q -viewSelected $panel`;
				enableIsolateSelect $panel (!`isolateSelect -q -state $panel`);
 
					if (size($isolate_original) == 0)
						$isolate_original = $default;
 
				editRenderLayerGlobals -currentRenderLayer $isolate_original;
			}
		}
	}
}

Hi there, 

I've written the above code. As you may know, Maya does not isolate an object when on a Render Layer. As someonw who uses them a lot it is very annoying.

I've attempted to write a script that will toggle back to the defaultRednerLayer, isolate an object and then toggle back to the previous render layer.

Everything is working as expected....however when going back to the defaultRenderLayer, the script still remembers the global string from previous excecution.

Is there a way to clear a global string on a 2nd excecution of a script? Or am I totally doing everything the wrong way and in fact there is possibly a better way to approach this whole thing?

This is beginning to reach the limits of my MEL capability. :(( 

You could make your global string variable a global string Array with one entry.

Then use the "clear" Mel command to reset it to an empty array. 

 I would put this action first so it would reset the variable before doing the rest of the script

Hope this wiil help. 

Cool idea, thanks Pilou. Seems to work for me now. 

When I meant Isolate selected objects on render layer not working, I meant things like faces which does not work! 

global string $isolate_original[];
 
// source isolate.mel; isolate;
 
global proc isolate(){
 
	global string $isolate_original[];
	string $current = `editRenderLayerGlobals -q -currentRenderLayer`;
	string $default = "defaultRenderLayer";
	string $visPanel[] = `getPanel -vis`;
 
	if (size($visPanel)>0)
	{
		for ($panel in $visPanel)
			if (`match "^modelPanel" $panel`=="modelPanel")
			{
				if ($current!= $default) 
				{
					$mode=`modelEditor -q -viewSelected $panel`;
					enableIsolateSelect $panel (!`isolateSelect -q -state $panel`);
					editRenderLayerGlobals -currentRenderLayer $default;
					$isolate_original = { $current };
 
 
				}
			else 
				{
					$mode=`modelEditor -q -viewSelected $panel`;
					enableIsolateSelect $panel (!`isolateSelect -q -state $panel`);						
 
					 if (size($isolate_original[0])==0)
						editRenderLayerGlobals -currentRenderLayer $default;
					 else
						editRenderLayerGlobals -currentRenderLayer $isolate_original[0];
 
					clear $isolate_original;
				}
			}
	}
}