Select to view content in your preferred language

How to show printed text from Script Tool?

219
3
11-12-2024 05:36 AM
TeresaBartolomei
New Contributor

Hi, I work on arcGIS Desktop 10.8 with python 2.7

Executing the python code from Geoprocessing window I've managed to print the count value of table's selected rows . The problem is that I want to store the code inside a toolbox, to do so I've added a script inside the toolbox but when I run it it get stuck and never show me the printed value.

This is the code:

import arcpy

tabella = "Name_of_the_table" 

conteggio_selezionato = 0

count = arcpy management GetCount(tabella)[0] # Restituisce una stringa
if count != "0":

with arcpy da SearchCursor(tabella, "*", "OBJECTID IS NOT NULL") as cursor:
for row in cursor:
conteggio_selezionato += 1

print "Numero di righe selezionate: {}" format(conteggio_selezionato)
else:
print "Nessuna riga selezionata "

0 Kudos
3 Replies
JakeSkinner
Esri Esteemed Contributor

Hi @TeresaBartolomei,

Replace print with arcpy.AddMessage.  Ex:

arcpy.AddMessage("Nessuna riga selezionata")

 

TeresaBartolomei
New Contributor

Same, actually it doesn' get stuck but it never ends executing:

TeresaBartolomei_0-1731420414660.png

maybe it's because it has no output parameter?

 

0 Kudos
AlfredBaldenweck
MVP Regular Contributor

That is going to be a different problem.

@JakeSkinner is right, replace print() with arcpy.AddMessage().

0 Kudos