I am creating a script tool, and what I’m trying to do is generate two CSV files from two different layers that belong to different maps. I’ve already tried this in a notebook, and it worked, but when I tried to adapt the script to use parameters, I received error code 000732: <value>: Dataset <value> does not exist or is not supported.
Here’s some useful information:
I first split the script into two parts, where all data comes from the same map, and it works as expected when used as a tool.
Then, I tried to run the tool with one of the two maps active, and the error message indicated that the issue is with the layer from the inactive map.
This leads me to believe that the problem might be due to not having all the layers in the same map. But having all the information in one map is not an option.
Here is the script:
import arcpy
import pandas as pd
import os
# Get the "Uso Actual" map
map_uso_actual = arcpy.GetParameter(0)
# Get the "PDU 2023 7ma Actualización" layer
layer_uso_actual = arcpy.GetParameter(1)
# Define the relevant fields
campo_uso_actual = "id_modif_uso"
campo_area = "sup_ha" # This field represents the area of each polygon
# Load the "Uso Actual" table into a Pandas DataFrame using TableToNumPyArray
tabla_actual = arcpy.da.TableToNumPyArray(layer_uso_actual, [campo_uso_actual, "uso_suelo", campo_area])
# Convert the table to a Pandas DataFrame
df_actual = pd.DataFrame(tabla_actual)
# Group 'df_actual' by 'id_modif_uso' and 'uso_suelo' to get the sum of the area
df_actual_agrupado = df_actual.groupby([campo_uso_actual, "uso_suelo"], as_index=False).agg({
campo_area: "sum"
})
# Export the result to a CSV file
output_csv = r"C:\EsriTraining\resumen_uso_actual2.csv"
df_actual_agrupado.to_csv(output_csv, index=False)
# Get the "Uso Propuesto" map
map_uso_propuesto = arcpy.GetParameter(2)
# Get the "PDU 2023 7ma Actualización" layer
layer_uso_propuesto = arcpy.GetParameter(3)
# Define the relevant fields for the proposed use
campo_uso_propuesto = "m_id_modif_uso"
campo_area = "sup_ha" # This field represents the area of each polygon
# Load the "Uso Propuesto" table into a Pandas DataFrame using TableToNumPyArray
tabla_propuesto = arcpy.da.TableToNumPyArray(layer_uso_propuesto, [campo_uso_propuesto, "uso_suelo", campo_area])
# Convert the table to a Pandas DataFrame
df_propuesto = pd.DataFrame(tabla_propuesto)
# Group 'df_propuesto' by 'm_id_modif_uso' and 'uso_suelo' to get the sum of the area
df_propuesto_agrupado = df_propuesto.groupby([campo_uso_propuesto, "uso_suelo"], as_index=False).agg({
campo_area: "sum"
})
# Export the result to a CSV file
output_csv1 = r"C:\EsriTraining\resumen_uso_actual1.csv"
df_propuesto_agrupado.to_csv(output_csv1, index=False)
First, some minor housekeeping:
When posting code to the forums, it's generally advisable to use a code block for easier reading. Click the ellipsis button ("..."), then click the code button ("</>"). Python should be an option in the menu. If you ever need to post Arcade in the future, the JavaScript option works closely enough.
Now, regarding your code:
What are the datatypes on each of those parameters? And specifically what line does the error message cite? Oftentimes, that can be helpful in narrowing down the issue.
It sounds like something somewhere along the way is effectively trying to call
arcpy.mp.ArcGISProject('Current')
, but I don't see where that could be happening, yet.