Sometimes, model builders do not provide all the necessary information about the processes they perform. Let's explore how to add useful information for the user and modify the messages output from geoprocessing. This way, we will be able to extract information from each instrument performed separately.
In this post, we'll explore the process.
In the first step, create a new Python script.
Add a name to the script by right-clicking and selecting 'Properties,' similar to ModelBuilder.
Now, select the 'Execution' button. There is pre-created code in the window.
Since we are going to create our logic, highlight and delete all the code in this window.
It's time to write some code.
mb_message = arcpy.GetParameterAsText(0)
my_text = arcpy.GetParameterAsText(1)
Now, let's add them as messages to the geoprocessing window.
arcpy.AddMessage(mb_message)
arcpy.AddMessage(my_text)
To save the changes, select 'OK.'
Open the window again and go to the parameters.
There, set the two parameters that you want to display in the user interface.
Now, it's time to set the parameter types and whether they are required to be entered. Configure them as follows.
Close the window with 'OK,' and it's time for a test. Open geoprocessing and enter an example text.
Choose 'RUN'.
Open 'View Details'.
You will see the correctly entered text. Now, it's time to embed our tool in ModelBuilder.
For this purpose, I will use already made models.
Pull in the model 'Add multiple fields to DB' and 'Add Messages'.
Link to the rest of the model elements.
Similar to 'my_text,' add an additional annotation, such as 'File named %Name% has been read and added to GDB'.
Validate and save the model, then run it.
The output should display each added element along with our custom message.
For greater clarity, add the message output to one more model. This is the pattern to delete a field from all layers in the database.
The messages of this model are rather vague and do not contain information about the operation performed. They currently look like this.
With the addition of our script, we will add more clarity to them. Add our custom block.
Connect it to the output of the delete operation.
Also, add the 'my_text' parameter.
Edit the text so that it carries more information.
Validate, save, and run our model. Review the result.
Much more information about the user is now displayed.
In the following posts, we will see how to save this information in a log file locally on the computer.
Thanks for your attention, for more posts subscribe to our newsletter.