{"id":415,"date":"2013-04-04T10:26:50","date_gmt":"2013-04-04T10:26:50","guid":{"rendered":"http:\/\/oneteamgis.wordpress.com\/?p=415"},"modified":"2025-09-11T16:30:39","modified_gmt":"2025-09-11T14:30:39","slug":"creare-un-contatore-numerico-crescente-sequential-numbers-in-un-campo-utilizzando-il-python-nel-the-field-calculator-attenti-a-come-scrivete-lo-script","status":"publish","type":"post","link":"https:\/\/gis.oneteam.it\/index.php\/2013\/04\/04\/creare-un-contatore-numerico-crescente-sequential-numbers-in-un-campo-utilizzando-il-python-nel-the-field-calculator-attenti-a-come-scrivete-lo-script\/","title":{"rendered":"Creare un contatore numerico crescente (sequential numbers) utilizzando Python nel Field Calculator: attenti a come scrivete lo script!"},"content":{"rendered":"<div align=\"justify\">\n<p>Grazie alla segnalazione di un nostro utente che ha avuto difficolt\u00e0 nel generare un contatore numerico crescente (<strong>Sequential ID<\/strong>) all&#8217;interno di una tabella, segnaliamo la procedura corretta per compilare un campo utilizzando un apposito script.<\/p>\n<p>Fino ad oggi si riusciva ad utilizzare senza problemi la formula che trovate a questo <a href=\"http:\/\/support.esri.com\/en\/knowledgebase\/techarticles\/detail\/38517\" target=\"_blank\">link<\/a>.<\/p>\n<p>Quel che abbiamo notato per\u00f2 \u00e8 che ora lo script, che utlizza il linguaggio <strong>Python<\/strong>, va scritto ponendo molta attenzione alle dentature altrimenti verr\u00e0 generato un errore e la procedura non funzioner\u00e0! Cosa che precedentemente non accadeva.<\/p>\n<p>Pertanto, dopo aver creato un nuovo campo Short Integer, aperto il comando Field Calculator, selezionato Python e attivato lo Show Codeblock scrivete la formula come segue:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\nrec=0\ndef autoIncrement():\n\tglobal rec\n\tpStart = 1\n\tpInterval = 1\n\tif (rec == 0):\n\t\trec = pStart\n\telse:\n\t\trec += pInterval\n\treturn rec\n<\/pre>\n<p>E poi sotto:<\/p>\n<p>autoIncrement()<\/p>\n<p>Osservate le indentature! Ora sono fondamentali!<\/p>\n<p style=\"text-align:center;\"><a href=\"https:\/\/gis.oneteam.it\/wp-content\/uploads\/2013\/04\/sequentialid1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-418\" alt=\"SequentialID\" src=\"https:\/\/gis.oneteam.it\/wp-content\/uploads\/2013\/04\/sequentialid1.jpg?w=235\" width=\"235\" height=\"300\" srcset=\"https:\/\/gis.oneteam.it\/wp-content\/uploads\/2013\/04\/sequentialid1.jpg 543w, https:\/\/gis.oneteam.it\/wp-content\/uploads\/2013\/04\/sequentialid1-236x300.jpg 236w\" sizes=\"auto, (max-width: 235px) 100vw, 235px\" \/><\/a><\/p>\n<p style=\"text-align:left;\">In tabella verr\u00e0 quindi calcolato correttamente il campo!<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Grazie alla segnalazione di un nostro utente che ha avuto difficolt\u00e0 nel generare un contatore numerico crescente (Sequential ID) all&#8217;interno di una tabella, segnaliamo la procedura corretta per compilare un campo utilizzando un apposito script. Fino ad oggi si riusciva ad utilizzare senza problemi la formula che trovate a questo link. Quel che abbiamo notato&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,14,29,1016],"tags":[70,131,134,175,256,322,411,507,516],"class_list":["post-415","post","type-post","status-publish","format-standard","hentry","category-arcgis-for-desktop","category-articoli-tecnici","category-python","category-tips-tricks","tag-arcgis","tag-calculator","tag-campo","tag-contatore","tag-field","tag-id","tag-numerico","tag-script","tag-sequential"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/gis.oneteam.it\/index.php\/wp-json\/wp\/v2\/posts\/415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gis.oneteam.it\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gis.oneteam.it\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gis.oneteam.it\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gis.oneteam.it\/index.php\/wp-json\/wp\/v2\/comments?post=415"}],"version-history":[{"count":1,"href":"https:\/\/gis.oneteam.it\/index.php\/wp-json\/wp\/v2\/posts\/415\/revisions"}],"predecessor-version":[{"id":13256,"href":"https:\/\/gis.oneteam.it\/index.php\/wp-json\/wp\/v2\/posts\/415\/revisions\/13256"}],"wp:attachment":[{"href":"https:\/\/gis.oneteam.it\/index.php\/wp-json\/wp\/v2\/media?parent=415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gis.oneteam.it\/index.php\/wp-json\/wp\/v2\/categories?post=415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gis.oneteam.it\/index.php\/wp-json\/wp\/v2\/tags?post=415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}