I've made a simple model in ModelBuilder, ArcGIS 10.1. The model take a file in gdb, select two consecutive years, and calculate the near distances between the actual and previous year. As the near distance values are attached to attribute table of the "input file", I want to export the feature with attached attributes to another geodatabase, and export my attribute table to .csv.
The model seems to work fine when I run it manually for every couple of years (years 2005-2009: 2005-2006, 2006-2007, 2007-2008, 2008-2009). However, when I run it as a batch process, my output results are all the same and contains all years, not only the selected ones.
How can I correctly export the final outputs per year? I tried to alter the name of Output Feature Class to bb_%n%
following this post: Unexpected result using ModelBuilder in batch?, however it does not to seems to influence my output.
and my Batch process:
Python snippet:
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# near_distance.py
# Created on: 2017-04-11 10:46:59.00000
# (generated by ArcGIS/ModelBuilder)
# Usage: near_distance <Actual_year> <Previous_year> <Output_Feature_Class__BB_per_year_> <a1>
# Description:
# identify old and new year
#
# measure neirest neighbor distance
# ---------------------------------------------------------------------------
# Set the necessary product code
# import arcinfo
# Import arcpy module
import arcpy
# Load required toolboxes
arcpy.ImportToolbox("C:/Users/maria/UEL/Projects/2017_wind_beetle_from_aerial/Ferencik/analyzed_data/export_attributeTable.tbx")
# Script arguments
Actual_year = arcpy.GetParameterAsText(0)
if Actual_year == '#' or not Actual_year:
Actual_year = "\"year\" = 2006" # provide a default value if unspecified
Previous_year = arcpy.GetParameterAsText(1)
if Previous_year == '#' or not Previous_year:
Previous_year = "\"year\" = 2005" # provide a default value if unspecified
Output_Feature_Class__BB_per_year_ = arcpy.GetParameterAsText(2)
if Output_Feature_Class__BB_per_year_ == '#' or not Output_Feature_Class__BB_per_year_:
Output_Feature_Class__BB_per_year_ = "a1" # provide a default value if unspecified
a1 = arcpy.GetParameterAsText(3)
if a1 == '#' or not a1:
a1 = "C:\\Users\\maria\\UEL\\Projects\\2017_wind_beetle_from_aerial\\Ferencik\\analyzed_data\\near_distance.gdb\\a1" # provide a default value if unspecified
# Local variables:
bb_integer = "C:\\Users\\maria\\UEL\\Projects\\2017_wind_beetle_from_aerial\\Ferencik\\analyzed_data\\BB_corrected_by_location.gdb\\bb_integer"
BB_n = Previous_year
Actual_year_completed = BB_n
BB_n_1 = Actual_year
Output_geodatabase = "C:\\Users\\maria\\UEL\\Projects\\2017_wind_beetle_from_aerial\\Ferencik\\analyzed_data\\near_distance.gdb"
t__Name__csv = "C:\\Users\\maria\\UEL\\Projects\\2017_wind_beetle_from_aerial\\Ferencik\\output_data\\Results\\near_distance2\\t_%Name%.csv"
# Process: Select (2)
arcpy.Select_analysis(bb_integer, BB_n_1, Actual_year)
# Process: Select
arcpy.Select_analysis(bb_integer, BB_n, Previous_year)
# Process: Near
arcpy.Near_analysis(BB_n_1, "C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select", "", "NO_LOCATION", "NO_ANGLE")
# Process: Feature Class to Feature Class
arcpy.FeatureClassToFeatureClass_conversion(Actual_year_completed, Output_geodatabase, Output_Feature_Class__BB_per_year_, "", "FID_bb_15 \"FID_bb_15\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_15,-1,-1;FID_aoifin \"FID_aoifin\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_aoifin,-1,-1;FID_aoi \"FID_aoi\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_aoi,-1,-1;FID_clean_2011 \"FID_clean_2011\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_clean_2011,-1,-1;Id \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id,-1,-1;FID_all_2015_true \"FID_all_2015_true\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2015_true,-1,-1;Id_1 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_1,-1,-1;FID_all_2015_false \"FID_all_2015_false\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2015_false,-1,-1;Id_12 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12,-1,-1;FID_all_2013_false \"FID_all_2013_false\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2013_false,-1,-1;Id_12_13 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12_13,-1,-1;FID_all_2011_infra \"FID_all_2011_infra\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2011_infra,-1,-1;Id_12_13_14 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12_13_14,-1,-1;FID_all_2009_infra \"FID_all_2009_infra\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2009_infra,-1,-1;Id_12_13_14_15 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12_13_14_15,-1,-1;FID_all_2008_infr \"FID_all_2008_infr\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2008_infr,-1,-1;Id_12_13_14_15_16 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12_13_14_15_16,-1,-1;FID_all_2008_farba \"FID_all_2008_farba\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2008_farba,-1,-1;Id_12_13_14_15_16_17 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12_13_14_15_16_17,-1,-1;FID_all_2005_farba \"FID_all_2005_farba\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2005_farba,-1,-1;Id_12_13_14_15_16_17_18 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12_13_14_15_16_17_18,-1,-1;FID_mlc03 \"FID_mlc03\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_mlc03,-1,-1;ID_12_13_14_15_16_17_18_19 \"ID\" true true false 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,ID_12_13_14_15_16_17_18_19,-1,-1;GRIDCODE \"GRIDCODE\" true true false 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,GRIDCODE,-1,-1;FID_zonacia_2016_navrh \"FID_zonacia_2016_navrh\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_zonacia_2016_navrh,-1,-1;OBJECTID_1 \"OBJECTID\" true true false 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,OBJECTID_1,-1,-1;ZONA \"ZONA\" true true false 3 Text 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,ZONA,-1,-1;Nazov_zony \"Nazov_zony\" true true false 70 Text 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Nazov_zony,-1,-1;Zona_OP \"Zona_OP\" true true false 40 Text 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Zona_OP,-1,-1;SOP \"SOP\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,SOP,-1,-1;Shape_Leng \"Shape_Leng\" true true false 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Shape_Leng,-1,-1;FID_forest_cleaned_from_1997_JPRL \"FID_forest_cleaned_from_1997_JPRL\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_forest_cleaned_from_1997_JPRL,-1,-1;Id_12_13_14_15_16_17_18_19_20 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12_13_14_15_16_17_18_19_20,-1,-1;FID_zonacia_2016_navrh_1 \"FID_zonacia_2016_navrh_1\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_zonacia_2016_navrh_1,-1,-1;OBJECTID_12 \"OBJECTID\" true true false 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,OBJECTID_12,-1,-1;ZONA_1 \"ZONA\" true true false 3 Text 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,ZONA_1,-1,-1;Nazov_zony_1 \"Nazov_zony\" true true false 70 Text 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Nazov_zony_1,-1,-1;Zona_OP_1 \"Zona_OP\" true true false 40 Text 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Zona_OP_1,-1,-1;SOP_1 \"SOP\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,SOP_1,-1,-1;Shape_Leng_1 \"Shape_Leng\" true true false 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Shape_Leng_1,-1,-1;year \"year\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,year,-1,-1;FID_bb_11 \"FID_bb_11\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_11,-1,-1;FID_bb_13 \"FID_bb_13\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_13,-1,-1;FID_bb_09 \"FID_bb_09\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_09,-1,-1;FID_bb_08 \"FID_bb_08\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_08,-1,-1;FID_bb_07 \"FID_bb_07\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_07,-1,-1;FID_bb_06 \"FID_bb_06\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_06,-1,-1;FID_bb_05 \"FID_bb_05\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_05,-1,-1;ORIG_FID \"ORIG_FID\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,ORIG_FID,-1,-1;Shape_Length \"Shape_Length\" true true true 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Shape_Length,-1,-1;Shape_Area \"Shape_Area\" true true true 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Shape_Area,-1,-1;Shape_length_1 \"Shape_length_1\" true true false 0 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Shape_length_1,-1,-1;Shape_area_1 \"Shape_area_1\" true true false 0 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Shape_area_1,-1,-1;NEAR_FID \"NEAR_FID\" true true false 0 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,NEAR_FID,-1,-1;NEAR_DIST \"NEAR_DIST\" true true false 0 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,NEAR_DIST,-1,-1", "")
# Process: exportTable2
arcpy.gp.toolbox = "C:/Users/maria/UEL/Projects/2017_wind_beetle_from_aerial/Ferencik/analyzed_data/export_attributeTable.tbx";
# Warning: the toolbox C:/Users/maria/UEL/Projects/2017_wind_beetle_from_aerial/Ferencik/analyzed_data/export_attributeTable.tbx DOES NOT have an alias.
# Please assign this toolbox an alias to avoid tool name collisions
# And replace arcpy.gp.exportTable2(...) with arcpy.exportTable2_ALIAS(...)
arcpy.gp.exportTable2(Output_geodatabase, t__Name__csv)