[GIS] Creating custom tool using Python script exported from ModelBuilder

arcpymodelbuilder

I created some ModelBuilder for some customization to reduce time in our routine process.

I exported my ModelBuilder to python script by availability of export options.

It doesn't work if i bring to tool bar.

any one suggest me clearly how to access the script in tool bar with some standard clear steps to follow?

as well as whether i need to do any modification on my exported python script?

Best Answer

Here is a list of things to consider before exporting models to Python:

  • If your model uses an iterator, the iteration logic will not be exported and will have to be replaced with looping statements in Python.
  • If your model used a Model only tool such as Merge Branch, Collect Values, or Calculate Value, these tools will not run properly in Python; they may execute without error, but nothing happens and your script doesn't work as expected. In some cases, the Python script will fail at a later point. You need to implement the equivalent Python functionality these Model only tools provide.
  • If your model used inline variable substitution such as %workspace%, %scratchworkspace%, %n%, %i%, or %variable name%, you will have to replace these with the correct value in the Python script.
  • If your model used layers or table views from ArcMap or ArcGlobe, those layers or table views will have to be created or the data will need to be fully referenced in the script.
  • If your model used layers or table views that are not created within the original model, those layers or table views will have to be created in the script using tools such as MakeFeatureLayer and MakeTableView.
  • If your model included sub-models, the contents within those sub-models will not be exported. Instead, the toolbox will have to be referenced and the model tool will need to be called inside the script.
  • If you expect to be overwriting data, set the overwriteOutput property to True. arcpy.env.overwriteOutput = True

  • Variables in your model are converted directly into Python variables in the exported script. You need to avoid naming your model variables the same as Python's reserved keywords (for example, class, global, return). For a full list of reserved keywords, use Python's keyword module.

  • If your model has an input variable type that is a FeatureSet or RecordSet, it will be exported as an in-memory feature class such as "in_memory\{E83BC42B-3578-4D20-A817-5F2AF3F5D05E}". You need to update this variable in Python with a path to a valid dataset or create a script tool where the input data type is a feature set.

Related Question