I have the following script:

import arcpy
from arcpy import mapping

arcpy.env.workspace = r"C:\GIS\Test"
mxd = arcpy.mapping.MapDocument(r"C:\GIS\Test\Mxd_to_shape.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]

shp_input = "hellow.shp"
layer_output = "test"

layer = arcpy.mapping.Layer(layer_output)

del mxd

arcpy.AddMessage("Ended process")

As you can see, I have defined variables in the previous script. However, I need these variables to remain "open" to later transform the script into a sub-tool of a ModelBuilder model. The need is that apparently having the pre-set variables in the script, wanting to change them as parameters in ModelBuilder does not work.


1 Answer 1


I recommend reviewing the ArcMap help topic on Integrating scripts within a model:

Python or other language scripts can be integrated into models by making the script into a script tool and adding the script tool to a model. This can be used when Python or other scripting language logic is needed to enhance a model or to access an external package or program from within ArcGIS.

The starting place for integrating scripts within models is the actual script. The script must be written in such a way that it can be integrated into the geoprocessing framework. For more information, refer to Writing a Python script.

Once the script is written, a script tool can be created and added to a toolbox. This script tool can be added to a model and used to bring additional functionality to the model.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.