Exporting a model
A model can be exported to a graphic or a Python script.
Exporting a model to a graphic
A model can be exported to a graphic that can be used in documentation, reports, and posters. To export a model to a graphic, follow the steps below:
- From the menu in ModelBuilder, point to and click Model > Export > To Graphic.
- Set the desired options in the Save As dialog box. Graphics can be saved to .bmp, .jpg, or Windows enhanced metafile (.emf) formats.
- Click OK.
Exporting a model to a Python script
An easy way to start writing scripts is to export a model you have created to a script, then modify the exported script. The script can be added to a toolbox or model as a script tool and run as any other tool. To export a model to a script, follow the steps below:
- From the menu in ModelBuilder, point to and click Model > Export > To Python Script.
- Click the Save in drop-down arrow and navigate to the location where you want to save your script.
- Type a file name for the script.
- Click Save.
Functionality to export models to JScript and VBScript has been removed from ModelBuilder at version 10.
Editing exported Python script
Any model created in ModelBuilder can be exported to a script. This can be one technique for furthering your model as well as seeing how tools and environments are used in a scripting environment.
Take the following points under consideration when exporting a model to a script:
- If you expect to be overwriting data, set the overwriteOutput property to True.
- If your model used layers or table views that weren't created within the original model, those layers or table views will have to created in the script using tools such as MakeFeatureLayer and MakeTableView.
- Data elements from your model are converted directly into variables in the exported script. Avoid naming data elements that will be incompatible in Python (for example, class, global, return). For a full list of reserved keywords, use Python's keyword module.
import keyword print keyword.kwlist
- If your model used any inline variable substitution such as %workspace%, %scratchworkspace%, %n%, %i%, or %variable name%, those will have to be substituted with the correct value.
- If your model used an iterator, the iteration logic will not be exported and will have to be replaced with the looping statements in Python.