I often run processes so big that take several days. I want to segment the process so instead of running a big input through the ModelBuilder I run smaller pieces of the same input and then, at the end I can easily merge the pieces.

I have already developed a Python Toolbox that does this. It is the split_and_run tool in the model below. In the execute() part of this tool I use arcpy.SplitByAttributes_analysis which I found to have problems with the iterator. Link to a further explanation of the problem: ARCGIS modelbuilder iterator dependency conflict with arcpy.SplitByAttributes_analysis

  def execute(self, parameters, messages):
          """The source code of the tool."""
          inFeature = parameters[0].valueAsText
          numBlocks = parameters[1].valueAsText
          workSpace = parameters[2].valueAsText

          """This function will create the new field with the coresponding indexes in order to create blocks of the input size"""
          arcpy.env.workspace = workSpace
          arcpy.MakeFeatureLayer_management (inFeature, "retalls")

          #We create a temporary field to divide with.
          arcpy.AddField_management("retalls", "temp", "LONG", "", "", "",
                        '', "NULLABLE")

          row_count = arcpy.GetCount_management(inFeature).getOutput(0)
          block_width = int(int(row_count)/int(numBlocks)) + 1 #We add one because when turning the fraction to an int it truncates to the floor.
          for i in range(0, int(numBlocks)):
              arcpy.SelectLayerByAttribute_management ("retalls", "NEW_SELECTION", '"OBJECTID" > ' + str(block_width * i) + 'and "OBJECTID" <= ' + str(block_width * (i+1)))
              arcpy.CalculateField_management("retalls", "temp", i, "PYTHON")#!!
        arcpy.SplitByAttributes_analysis("retalls", workSpace, "temp")


enter image description here

Since I have had zero luck with finding a solution of the iterator dependency, now I am trying a diferent approach, I have seen that there is the possibility to define a parameter as type Tool : DETool and ToolBox : DEToolbox so the new approach consists on passing a tool as a parameter of my custom Python Toolbox and executing it from within the Python Toolbox. Great idea! But the ModelBuilder pops this message: enter image description here

Is there anything I can do or should I look for another approach?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.