Select to view content in your preferred language

Batch Export Layers to TIF Toolkit Error

323
0
11-13-2023 03:04 AM
Labels (2)
chenjizhenchen
New Contributor

I used this code for batch exporting different layers:

import arcpy
import arcpy

def export_layers_to_tiff(selected_layers, output_folder)::
# Get the current ArcGIS project
project = arcpy.mp.ArcGISProject("CURRENT")

# Get the first layout in the project
layout = project.listLayouts()[0]

# Iterate over the layers selected by the user
for layer in selected_layers: # Enable layer visibility.
# Enable layer visibility
layer.visible = True

# Modify layer name, remove ' g/kg'.
modified_layer_name = layer.name.replace(" g/kg", "")

# Export layout to TIF format
output_path = os.path.join(output_folder, f"{modified_layer_name}.tif")
layout.exportToTIFF(output_path)

# Turn off layer visibility
layer.visible = False

arcpy.AddMessage("Export complete")

# Receive the output folder path parameter
output_folder = arcpy.GetParameterAsText(0)

# Receive the layers selected by the user
selected_layers = arcpy.GetParameter(1) 

export_layers_to_tiff(selected_layers, output_folder)

 

But keep getting this error: 
File "G:\GISPRO\ Toolbox/Toolkit.atbx#Script_atbx.py", line 35, in <module>
File "G:\GISPRO\ Toolbox/Toolbox.atbx#Script_atbx.py", line 22, in export_layers_to_tiff
File "C:\Program Files\ArcGIS\Pro/Resources\ArcPy\arcpy\utils.py", line 191, in fn_
return fn(*args, **kw)
File "C:\Program Files\ArcGIS\Pro/Resources\ArcPy\arcpy\_mp.py", line 1807, in exportToTIFF
return convertArcObjectToPythonObject(self._arc_object.exportToTIFF(*gp_fixargs((out_tif, resolution, color_mode, tiff_compression, )))
OSError: G:\Drawing\cen\SOC_upper_020.tif

Can you please tell me which part I should modify to complete this toolbox?

 

0 Kudos
0 Replies