How to print result of a custom model in Python using Model Builder and ArcPy

1032
1
11-21-2017 09:25 PM
AlexChen
New Contributor III

I have a custom model (called TOOLNAME) in a custom toolbox developed in Model Builder on ArcGIS 10.1 Desktop. The model takes two input parameters (SingleFDI_D and dayindex) and outputs a Derived parameter called "MaxFDI_DateTime" which is data of String type.

The model runs well within the Model Builder on ArcGIS Desktop.

I will need to execute the model in a standalone Python script as well.

My question is how to get the output of MaxFDI_DateTime out of the tool execution in Python.

arcpy.ImportToolbox(TOOL_DIR)
# The custom model should return a result in String, how to retrieve it here?
model_result = arcpy.{TOOLNAME}_{TOOLBOX_ALIAS}(SingleFDI_D, str(day))
0 Kudos
1 Reply
curtvprice
MVP Esteemed Contributor

model_result is returned from the tool as a Result object. (Most tools, not just custom ones, return one or more results in a result object.)

Either str(model_result) or model_result.GetOutput(0) should get your value

Result—Help | ArcGIS Desktop 

0 Kudos