Working around ArcGIS Pro inability to export models as Python code?
The reasons for the removal of this functionality are given at What happened To Export Script Button In ArcGIS Pro? by dflater-esristaff:
The ability to export from ModelBuilder to a Python script was removed from ArcGIS Pro 1.1 because it did not match user expectations to provide a one-to-one export of your model to Python. The scripts generated by exported models were missing nested sub-models, and did not include iterators, feedback loops, and in-line variable substitution. Models with these components would require major changes that most people who use Export are not able to make themselves. There is currently no plan to add this capability back into ArcGIS Pro.
I ceased exporting ModelBuilder models in ArcMap to Python code the day I discovered Copy As Python Snippet because the exported code was far harder to understand and debug due to the way it named variables, lacked understanding of iterators, etc.
I think it is far easier to learn ArcPy in ArcGIS Pro by using Copy Python Command to copy the exact Python syntax needed to run the geoprocessing tool with the same parameter settings previously used, and then paste it into a script that you are writing.
Alternatively, if you want to quickly run your model using ArcPy, dflater-esristaff also describes a workaround of:
Start by building and saving a model, then create a new Python script file (which is just a text file with .py extension), then using a text editor or Python IDE add lines to the new script to import arcpy, import the toolbox containing your model, and finally run the model.
...
import arcpy arcpy.ImportToolbox(r"c:\pathtotbx\Toolbox.tbx", "mytools") arcpy.MyModel_mytools(r"c:\modelinputs\Data.gdb\InputFeatures")
If you're simply looking to run an ArcGIS Pro model from a raw python script, simply use something like this:
import arcpy
arcpy.ImportToolbox(r"C:/Data/Toolboxname.tbx")
arcpy.Toolboxname.Modelname()
This will run a model ('Modelname') from a specified Toolbox ('Toolboxname')