You are here:
Automating your work with models
You can create a model tool that allows the user to interactively create features or records as tool input. To do so, create an input variable of data type Feature Set or Record Set, set its template schema and symbology properties (Feature Set only), and make the variable a model parameter. When the model is run from its dialog box, you'll be able to interactively create the input features or records for the tool.
Applications where this interactive functionality is useful include:
- Creating the polygons to use to clip or erase features
- Adding points on the landscape to determine feature that are nearby
- Creating a new table using interactively entered rows with attributes
- Entering XY coordinates to convert to points
- Setting the observer points to calculate the viewshed
- Adding locations to visit sequential points on a network in the order specified
- Setting the start and destination points to use in determining the least-cost path across a landscape
For example, you might want to create a tool that allows a user to interactively define in the display the clipping polygon or polygons that will be used to clip input features. This means the user doesn't have to create a new feature class and initiate an edit session to create the clipping feature or features before running the Clip tool.
For any geoprocessing tool that uses features or a table as input, you can exchange the feature or table input parameter for an interactive input parameter that allows the user to create the features in the display or to add the records that they want to use as inputs to a tool.
Creating a model tool to allow interactive input
To allow interactive input for a tool, you must create a model, that includes the tool you want to run using interactive feature input, then create a variable of type Feature Set (for feature input) or Record Set (for table input) that is used in place of a regular input feature class or table. By importing the schema and symbology for the Feature Set or Record Set variable from an existing layer, feature class or table, then setting the Feature Set or Record Set variable as a model parameter, when the model tool is opened from its dialog box, the interactive features or interactive records control will be exposed as an input parameter for the tool.
Before performing the steps to create the model tool, make sure you have an existing layer, feature class, or table from which you will import the schema and symbology (Feature Set only) to the Feature Set or Record Set. For features, you should make sure the schema of the existing feature layer or feature class is of the correct type (point, polyline or polygon), depending on the type of features you want the user to be able to draw in the display as input features to the tool. For example, if you want to use a Feature Set for the input clipping polygon, make sure you import the schema of a polygon feature layer or feature class. As well as importing the schema, you also import the symbology. So if you want your interactive features to be drawn in a particular color, or with a particular hatch symbol, you should create a layer using the symbology you want to import.
NOTE: The schema and symbology is taken and imported into the model. There is no reference to the original data once it is imported.
The following steps outline the process for creating a model tool that allows interactive input:
- Add the tool or tools you want to run using interactive input to a new model. This could just be one tool, or a number of tools strung together.
- Right-click the model diagram and click Create Variable.
- Select Feature Set as the variable's data type if you want to create an interactive feature control, or select Record Set if you want to create an interactive table record control, and click OK.
- Right-click the Feature Set (or Record Set) variable and click Properties.
- Click the Data Type tab and make sure the Select data type dropdown is set to Feature Set (or Record Set).
- Set a template dataset to apply to the features or table records that the user will create for the Feature Set or Record Set. The type of feature (point, polyline or polygon) and the symbology available to the user in the model tool's dialog box is based on the template feature class schema and symbology specified here. For table records, only the schema applies.
If you have a layer in the table of contents that contains the schema and symbology you want to apply to your Feature Set, click the dropdown and select the layer. Similarly, if you have a table containing the schema you want to apply to your Record Set, click the dropdown and select the table. Alternatively, click the browse button to navigate to a location on disk to import a layer file, a feature class or a table. If you import a layer from the table of contents, or a layer file from disk, you can take advantage of the symbology that is set. This is useful if you want the user of your tool to draw features using a particular color or pattern, for example, a hatch pattern for input clip polygons.
Remember that the schema and symbology is taken from the data and imported into the model where it is stored. There is no reference to the original data once it is imported. Changing, for example, a layer's symbology after it has been imported into the model for a particular Feature Set variable, will have no affect on the imported schema and symbology. The Data Type tab will always list the last schema and symbology that was imported.
- Double-click the tool in the model to set its parameter values. Set the Feature Set or Record Set as the input for the tool. In the case of a tool such as Clip, the Input Features should be set to a feature layer or feature class (point, polyline, or polygon) that you want to be clipped. The Feature Set variable should be set as the value for the Clip Features parameter. In this case, the schema set for the Feature Set was a polygon feature layer.
- Rename the input and output variables to be the names you want for labels for the parameters on your model tool's dialog box.
- Set model parameters for the input and output variables by right-clicking each one and clicking Model Parameter.
- Save and close the model.
- Make sure that the parameters are ordered in the way you want them ordered on the tool's dialog box. For example, you may want the Input parameters at the top of the dialog box and the output parameters at the bottom. Right-click the model in the ArcToolbox window and click Properties, then click the Parameters tab. You can change the order of how the parameters will look in the dialog box by clicking a parameter and clicking the up or down arrow.
- Double-click the tool in the ArcToolbox window to open its dialog box.
For interactive feature input, the user of your tool clicks the Add feature button (, , or depending on the data type) then draws the features they want to use as input in the display. In the example, the user draws the polygons that will be used as the Clip features to clip portions of the input features.
For interactive record input, the user clicks the Add record button , then types the values for attributes.
Once all the desired input features are drawn, or input records are added, and the tool is run, the interactively created input features or records are used to create the tool's result.
NOTE: It is not possible to write to a Feature Set, so if you want to allow interactive features or records as input to tools such as Near or Calculate Field where the output is the same as the input (derived data), add the Copy features or Copy rows tool to the model and connect the Feature Set or Record Set variable as input to that. Connect the output from the Copy features or Copy rows tool as input to the tool you want to run on the Feature Set or Record Set.
NOTE: The feature set and record set parameter control are disabled in tool layers.
There are some useful tips and tricks to know when adding features interactively, such as using the tools on the Draw toolbar, entering coordinates to draw features in a specific location, entering a specific radius or area for a circle, and adding input features that were drawn interactively back to the display after the tool is run.
Learn more about using the interactive feature and record input controls
Altering an existing model to use interactive feature or record inputs
You may have an existing model tool that you want to modify to use interactive feature or table record inputs. The first example below explains how to alter an existing model to allow interactive input features. The second example explains how to alter an existing model to allow interactive table record inputs.
Example 1: Altering a model to allow interactive feature input
A model tool calculates the least-cost path across a landscape using a starting point and a destination point layer as inputs. This model could be made more user-friendly by allowing the user to interactively enter these two points.
The followings steps outline the process to alter your existing model to allow interactive feature inputs:
Example 2: Altering a model to allow interactive record input
- Right-click the input variables in your model that you want to set as interactive feature inputs, and click Properties.
- Click the Data Type tab and set the data type to Feature Set. This is the data type that will expose the interactive feature input control on your model tool's dialog box. Import the schema and symbology that you want to apply to the features that will be added interactively. This could be the layer that was attached as the original input.
- Save and close your model and open the model tool's dialog box by double-clicking the tool in the ArcToolbox window. The user of your tool can now interactively enter the input features for your tool.
A model tool that takes a table with XY coordinates in decimal degrees and converts the coordinate values to points that are buffered and placed on a map could be made more user-friendly by allowing the user to input the XY coordinates interactively for each record.
The following steps outline the process to alter your existing model to allow interactive record inputs:
- Right-click the input variable in your model that you want to set as interactive record inputs, and click Properties. This is a table that is an input for a tool in your model.
- Click the Date Type tab and set the data type to Record Set. This is the data type that will expose the interactive record input control on your model tool's dialog box. Import the schema of an existing table that you want to apply to the records you add interactively. This could be the table that was attached as the original input. The schema chosen determines the fields that will be available for each record added.
- Save and close your model and open the model tool's dialog box by double-clicking the tool in the ArcToolbox window. The user of your tool can now interactively enter the input records for your tool and assign attribute values using the attribute editor window.