Good day,
My attempts to package my project keep failing with the error code tatus: "Failed ErrorMessage: ERROR 001659: Consolidating toolbox C:\GIS\Seg_Processing_ARCPRO\Seg_Processing_ARCPRO.tbx"
The model works fine when I run it; however it includes and Iterator. I'm aware that the Iterator function is strictly a model tool and does not translate to python script. Could this be the reason for the failure to package my project?
TIA
The error...
001659: Consolidating toolbox <value>
has a suggestion. Did you get the report from
Analyze Tools For Pro (Data Management) ?
Thanks for the feedback. I ran the Analyze Tools For Pro and received the below...
"ERROR 000989: Python syntax error: within script C:\GIS\Seg_Processing_ARCPRO\Seg_Processing_ARCPRO.aprx
Failed to execute (AnalyzeToolsForPro)."
Do you know if it is possible to isolate where exactly the syntax error is occurring?
Have you opened the script up in a python IDE to check for syntax errors?
If it is a model, then try
If it is relatively short, you can post a copy of the code here
Essentially, in my project folder I have an input folder with shapefiles of (A) species distribution records (points) which I need to 'intersect' and spatially join with a large multipolygon shapefile stored within the project GDB (B). The output (the specific polygons from B which contain points from A) are then saved in a n output folder within the project folder. The toolbox I created with modelbuilder does this for me but when I try saving the project as a package the error as listed in my OP pops up. Below is the code from my model that I exported to python window (I see that Iterators are unwelcome in Python, perhaps that is the syntax error that is coming up?):
PS. Thank you vey much for your help, it is hugely appreciated!
# -*- coding: utf-8 -*-
"""
Generated by ArcGIS ModelBuilder on : 2020-11-16 13:04:46
"""
import arcpy
import os
def FeatureClassGenerator(workspace, wild_card, feature_type, recursive) :
with arcpy.EnvManager(workspace = workspace):
dataset_list = [""]
if recursive:
datasets = arcpy.ListDatasets()
dataset_list.extend(datasets)
for dataset in dataset_list:
featureclasses = arcpy.ListFeatureClasses(wild_card, feature_type, dataset)
for fc in featureclasses:
yield os.path.join(workspace, dataset, fc), fc
def Model(): # Segment Processing
# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = False
Fixed_Segments_5_ = "C:\\GIS\\Seg_Processing_ARCPRO\\Seg_Processing_ARCPRO.gdb\\Fixed_Segments"
Input_Species_For_Processing = "C:\\GIS\\Seg_Processing_ARCPRO\\Input\\Input_Species_For_Processing"
for FeatureClass, Name in FeatureClassGenerator(Input_Species_For_Processing, "*.shp", "POINT", "RECURSIVE"):
# Process: Select Layer By Location (Select Layer By Location) (management)
Fixed_Segments_Layer, Output_Layer_Names, Count = arcpy.management.SelectLayerByLocation(in_layer=[Fixed_Segments_5_], overlap_type="CONTAINS", select_features=FeatureClass, search_distance="", selection_type="NEW_SELECTION", invert_spatial_relationship="NOT_INVERT")
# Process: Spatial Join (Spatial Join) (analysis)
Name = "FeatureClass"
_Name_shp = fr"C:\GIS\Seg_Processing_ARCPRO\Output\{Name}.shp"
arcpy.analysis.SpatialJoin(target_features=Fixed_Segments_Layer, join_features=FeatureClass, out_feature_class=_Name_shp, join_operation="JOIN_ONE_TO_ONE", join_type="KEEP_ALL", field_mapping="fid_1 \"fid_1\" true true false 8 Double 0 0,First,#,Fixed_Segments_Layer,fid_1,-1,-1;cat \"cat\" true true false 4 Long 0 0,First,#,Fixed_Segments_Layer,cat,-1,-1;ogc_fid \"ogc_fid\" true true false 4 Long 0 0,First,#,Fixed_Segments_Layer,ogc_fid,-1,-1;area \"area\" true true false 8 Double 0 0,First,#,Fixed_Segments_Layer,area,-1,-1;region \"region\" true true false 254 Text 0 0,First,#,Fixed_Segments_Layer,region,0,254;Natural_me \"Natural_me\" true true false 8 Double 0 0,First,#,Fixed_Segments_Layer,Natural_me,-1,-1;layer \"layer\" true true false 100 Text 0 0,First,#,Fixed_Segments_Layer,layer,0,100;path \"path\" true true false 200 Text 0 0,First,#,Fixed_Segments_Layer,path,0,200;Shape_Leng \"Shape_Length\" false true true 8 Double 0 0,First,#,Fixed_Segments_Layer,Shape_Length,-1,-1;Shape_Area \"Shape_Area\" false true true 8 Double 0 0,First,#,Fixed_Segments_Layer,Shape_Area,-1,-1", match_option="INTERSECT", search_radius="", distance_field_name="")
if __name__ == '__main__':
# Global Environment settings
with arcpy.EnvManager(scratchWorkspace=r"C:\GIS\Seg_Processing_ARCPRO\Seg_Processing_ARCPRO.gdb", workspace=r"C:\GIS\Seg_Processing_ARCPRO\Seg_Processing_ARCPRO.gdb"):
Model()
@OliverCowan you forgot to past within code blocks.
Click on the 3 dots, ... , then select the </> , then select Python and insert your code to get it formatted. as in this example from your code
# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = False
which begs the question... do you want to overwrite outputs? or not.
Are all your data locateable?
On a quick look, I can't see where if recursive is set
Did you run the compatability check I suggested?
,
# -*- coding: utf-8 -*-
"""
Generated by ArcGIS ModelBuilder on : 2020-11-16 13:04:46
"""
import arcpy
import os
def FeatureClassGenerator(workspace, wild_card, feature_type, recursive) :
with arcpy.EnvManager(workspace = workspace):
dataset_list = [""]
if recursive:
datasets = arcpy.ListDatasets()
dataset_list.extend(datasets)
for dataset in dataset_list:
featureclasses = arcpy.ListFeatureClasses(wild_card, feature_type, dataset)
for fc in featureclasses:
yield os.path.join(workspace, dataset, fc), fc
def Model(): # Segment Processing
# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = True
Fixed_Segments_5_ = "C:\\GIS\\Seg_Processing_ARCPRO\\Seg_Processing_ARCPRO.gdb\\Fixed_Segments"
Input_Species_For_Processing = "C:\\GIS\\Seg_Processing_ARCPRO\\Input\\Input_Species_For_Processing"
for FeatureClass, Name in FeatureClassGenerator(Input_Species_For_Processing, "*.shp", "POINT", "RECURSIVE"):
# Process: Select Layer By Location (Select Layer By Location) (management)
Fixed_Segments_Layer, Output_Layer_Names, Count = arcpy.management.SelectLayerByLocation(in_layer=[Fixed_Segments_5_], overlap_type="CONTAINS", select_features=FeatureClass, search_distance="", selection_type="NEW_SELECTION", invert_spatial_relationship="NOT_INVERT")
# Process: Spatial Join (Spatial Join) (analysis)
Name = "FeatureClass"
_Name_shp = fr"C:\GIS\Seg_Processing_ARCPRO\Output\{Name}.shp"
arcpy.analysis.SpatialJoin(target_features=Fixed_Segments_Layer, join_features=FeatureClass, out_feature_class=_Name_shp, join_operation="JOIN_ONE_TO_ONE", join_type="KEEP_ALL", field_mapping="fid_1 \"fid_1\" true true false 8 Double 0 0,First,#,Fixed_Segments_Layer,fid_1,-1,-1;cat \"cat\" true true false 4 Long 0 0,First,#,Fixed_Segments_Layer,cat,-1,-1;ogc_fid \"ogc_fid\" true true false 4 Long 0 0,First,#,Fixed_Segments_Layer,ogc_fid,-1,-1;area \"area\" true true false 8 Double 0 0,First,#,Fixed_Segments_Layer,area,-1,-1;region \"region\" true true false 254 Text 0 0,First,#,Fixed_Segments_Layer,region,0,254;Natural_me \"Natural_me\" true true false 8 Double 0 0,First,#,Fixed_Segments_Layer,Natural_me,-1,-1;layer \"layer\" true true false 100 Text 0 0,First,#,Fixed_Segments_Layer,layer,0,100;path \"path\" true true false 200 Text 0 0,First,#,Fixed_Segments_Layer,path,0,200;Shape_Leng \"Shape_Length\" false true true 8 Double 0 0,First,#,Fixed_Segments_Layer,Shape_Length,-1,-1;Shape_Area \"Shape_Area\" false true true 8 Double 0 0,First,#,Fixed_Segments_Layer,Shape_Area,-1,-1", match_option="INTERSECT", search_radius="", distance_field_name="")
if __name__ == '__main__':
# Global Environment settings
with arcpy.EnvManager(scratchWorkspace=r"C:\GIS\Seg_Processing_ARCPRO\Seg_Processing_ARCPRO.gdb", workspace=r"C:\GIS\Seg_Processing_ARCPRO\Seg_Processing_ARCPRO.gdb"):
Model()
my apologies-have amended above.
wrt to overwriting outputs at this stage it doesn't really matter but I have changed it to "=True".
Data should be locatable - the input shapefiles are within folders in the project folder.
The compatibility check reported a syntax error in script...
for FeatureClass, Name in FeatureClassGenerator(Input_Species_For_Processing, "*.shp", "POINT", "RECURSIVE"):
Is suspect you need to replace "RECURSIVE" with True
because this code section won't work since it is looking for a boolean
dataset_list = [""]
if recursive:
datasets = arcpy.ListDatasets()
dataset_list.extend(datasets)
and this block won't run at all since dataset_list is empty
for dataset in dataset_list:
featureclasses = arcpy.ListFeatureClasses(wild_card, feature_type, dataset)
for fc in featureclasses:
yield os.path.join(workspace, dataset, fc), fc