GISGP

How to add custom message to modelbuilder in arcgis pro

Published 5 days ago3 min read

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.

Picture 1

Add a name to the script by right-clicking and selecting 'Properties,' similar to ModelBuilder.

Picture 1

Now, select the 'Execution' button. There is pre-created code in the window.

Picture 1

Since we are going to create our logic, highlight and delete all the code in this window.

Picture 1

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.

Picture 884042255

Now, it's time to set the parameter types and whether they are required to be entered. Configure them as follows.

Picture 132149357

Close the window with 'OK,' and it's time for a test. Open geoprocessing and enter an example text.

Picture 1101684191

Choose 'RUN'.

Picture 925219497

Open 'View Details'.

Picture 496069504

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'.

Picture 806953093

Link to the rest of the model elements.

Picture 819362489

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.

Picture 333840106

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.

Picture 1191126688

The messages of this model are rather vague and do not contain information about the operation performed. They currently look like this.

Picture 354164238

With the addition of our script, we will add more clarity to them. Add our custom block.

Picture 1256637677

Connect it to the output of the delete operation.

Picture 1079047877

Also, add the 'my_text' parameter.

Picture 562318736

Edit the text so that it carries more information.

Picture 1739370384

Validate, save, and run our model. Review the result.

Picture 730778459

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.

Newsletter

Newsletter

* indicates required