I have a question regarding Python script for making a Heat Map Tool.
I  am making a Heat Map Tool where users can set the map extent, the tool will read the current scale of the map, then make a raster heat map layer using appropriate cell size and search radius depend on the map scale, and the new raster layer will appear on the TOC of the map document. I succeeded this part. 
But I also put a function that users can set the raster name, and the name will appear as a layer name too. 
The script is the below.
# Script arguments
heatMapTest2 = Output_Raster_Layer
heatMapTest2Name = 'Output Raster'
templist = heatMapTest2.split("\\")
layername = templist[-1]
MXD = arcpy.mapping.MapDocument("CURRENT")
dataFrame = arcpy.mapping.ListDataFrames(MXD)[0]
mapExtent = dataFrame.extent
scale = dataFrame.scale
Input_Layer_2 = Input_Layer
#Add new layer to the dataframe
result = arcpy.MakeRasterLayer_management(heatMapTest2, layername)
lyrLayer = result.getOutput(0)
arcpy.mapping.AddLayer(dataFrame, lyrLayer, "AUTO_ARRANGE")
This function does work if I use the ArcGIS from the remote, and the work environment is the same server as the remote. 
But I set the work environment in different server, it gives me an error message as the below.
Traceback (most recent call last):
File "Q:\GIS_Tools\HeatMapTool\Python\HeatMapTool_Incidents_Add_Reclass_para5_short.py", line 149, in <module>
result = arcpy.MakeRasterLayer_management(heatMapTest2, layername)
File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6479, in MakeRasterLayer
raise e
ExecuteError: ERROR 000582: Error occurred during execution.
Failed to execute (HeatMapAllWithOutputLayerPara).
 (line 149 is result = arcpy.MakeRasterLayer_management(heatMapTest2, layername))
 (line 149 is result = arcpy.MakeRasterLayer_management(heatMapTest2, layername))
Is there anybody who can tell why that happened? 
Solved! Go to Solution.
It is a bit difficult to deduce what may be the error based only on a mall part of the code, but in case you use the variable "layername" for other layers that are being created you should use arcpy.env.overwriteOuput = True or use unique names.
Please next time when posting code, use the syntax highlighting:
Posting Code blocks in the new GeoNet
Then your code would look like this:
# Script arguments
heatMapTest2 = Output_Raster_Layer
heatMapTest2Name = 'Output Raster'
templist = heatMapTest2.split("\\")
layername = templist[-1]
MXD = arcpy.mapping.MapDocument("CURRENT")
dataFrame = arcpy.mapping.ListDataFrames(MXD)[0]
mapExtent = dataFrame.extent
scale = dataFrame.scale
Input_Layer_2 = Input_Layer
#Add new layer to the dataframe
result = arcpy.MakeRasterLayer_management(heatMapTest2, layername)
lyrLayer = result.getOutput(0)
arcpy.mapping.AddLayer(dataFrame, lyrLayer, "AUTO_ARRANGE")
					
				
			
			
				
			
			
				
			
			
				
			
			
			
			
			
		I wouldn't use the result like that, rather you should use the layername variable in your call to add layer:
#Add new layer to the dataframe
arcpy.MakeRasterLayer_management(heatMapTest2, layername)
arcpy.mapping.AddLayer(dataFrame, layername, "AUTO_ARRANGE")
Thank you for the reply. I tried, but am still getting an error message like the below.
 I tried, but am still getting an error message like the below. 
Traceback (most recent call last):
  File "Q:\GIS_Tools\HeatMapTool\Python\HeatMapTool_Incidents_Add_Reclass_para5_revised_072414.py", line 149, in <module>
    arcpy.MakeRasterLayer_management(heatMapTest2, layername)
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6479, in MakeRasterLayer
    raise e
ExecuteError: ERROR 000582: Error occurred during execution.
Failed to execute (HeatMapAllWithOutputLayerParaRevised072414).
Failed at Thu Jul 24 17:43:35 2014 (Elapsed Time: 14.72 seconds)
It is a bit difficult to deduce what may be the error based only on a mall part of the code, but in case you use the variable "layername" for other layers that are being created you should use arcpy.env.overwriteOuput = True or use unique names.
Please next time when posting code, use the syntax highlighting:
Posting Code blocks in the new GeoNet
Then your code would look like this:
# Script arguments
heatMapTest2 = Output_Raster_Layer
heatMapTest2Name = 'Output Raster'
templist = heatMapTest2.split("\\")
layername = templist[-1]
MXD = arcpy.mapping.MapDocument("CURRENT")
dataFrame = arcpy.mapping.ListDataFrames(MXD)[0]
mapExtent = dataFrame.extent
scale = dataFrame.scale
Input_Layer_2 = Input_Layer
#Add new layer to the dataframe
result = arcpy.MakeRasterLayer_management(heatMapTest2, layername)
lyrLayer = result.getOutput(0)
arcpy.mapping.AddLayer(dataFrame, lyrLayer, "AUTO_ARRANGE")
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		