Arcade & Calculate field with text and incrementing number with a starting number and an interval

3499
20
12-15-2021 04:09 AM
AGP
by
Occasional Contributor

I have Python calculate field expression (.cal file) that does this but I'm trying to migrate it to Arcade.

It's not working. The number part is not incrementing and I guess it has to do with me not being able of defining 'rec' as a global variable.

This is the Python expression. How do I migrate the 'global rec' line to Arcade?

#Params
val_counter = 2498
prefix = 'PP_'
interval = 1
# -------------------------------------------
# Function
rec=0
def SetIDcode(val_counter, prefix, interval):
  global rec
  if (rec == 0):
    rec = val_counter
  else:
    rec += interval
  return (prefix+ str(rec))

 

0 Kudos
20 Replies
Brian_Wilson
Occasional Contributor III

Using Arcade when you don't have to seems like jumping through extra hoops to me. I have not seen any upside to it yet.

I am betting Arcade will go away before I need to learn it.

Brian

0 Kudos
jcarlson
MVP Esteemed Contributor

If you're working on desktop, you probably don't have to learn it, but a lot of the web stuff is being built around it. I use Arcade in Pro when I know the layer / expressions / etc. will need to transfer 1:1 to a web map or field app.

- Josh Carlson
Kendall County GIS
0 Kudos
JoeBorgione
MVP Emeritus

I'd be really surprised if Arcade has a short shelf life.  I'm sold on attribute rules and without Arcade, they don't happen.

ArcMap and ArcCatalog have one foot in the grave, there's just no denying it.

By the end of this week, all this stuff will be in my rear-view mirror, but I've had a ton of fun with Unix Scripts, AML, PERL, VB, VBA, Python, and Arcade over the years in various flavors of ESRI-Arc* products. You may notice I left out Avenue.  IMHO that along with ArcView was a mistake and luckily did have a short shelf life. (And somehow I never spent much time or energy with it...)

That should just about do it....
0 Kudos
jcarlson
MVP Esteemed Contributor

I know some folks who still maintain a "I'll wait this fad out" mentality about Python in ESRI products. You can probably imagine how that's going for them.

- Josh Carlson
Kendall County GIS
0 Kudos
Brian_Wilson
Occasional Contributor III

Almost every GIS person I know tried Python a few years ago and now ignores it. So it seems to be going fine. I'm at the other extreme, so much so that they had to change my job description. 

The good news about Arcade is that you can learn everything you need from it in about an hour. It's only a mistake if you think it's a programming language.

 

Brian_Wilson
Occasional Contributor III

Wait, was there someone at the top of this thread still waiting for an answer?  Now I feel I need to make amends for hijacking by actually answering the question. Where's Dan when we need him?

0 Kudos
jcarlson
MVP Esteemed Contributor

lol. Summons @DanPatterson 

Someone probably just needs a decent update cursor, but arcpy's outta my wheelhouse.

- Josh Carlson
Kendall County GIS
0 Kudos
jcarlson
MVP Esteemed Contributor

You know, I'm actually quite curious to know more about what you do, if you don't mind elaborating. My own experience in "GIS" is rather narrow, being almost exclusively focused on "cloudy map stuff" and the systems they're built on. So, lots of Python, js, SQL, and yes, Arcade. But I think there's always something valuable to learn from how other people work, especially when those processes are very different from my own.

- Josh Carlson
Kendall County GIS
0 Kudos
DanPatterson
MVP Esteemed Contributor

Taught university GIS (30+ years), consulted on same in multiple fields (eg. engineering, data analysis, medical, general modelling)... programming since 1968... basically your typical Geographer ("Geography is what Geographers Do").  Now retired .... sort of retired ... that is 😉


... sort of retired...
0 Kudos
DanPatterson
MVP Esteemed Contributor

"Avenue"... now "Arcade"  .

I got burned once learning a proprietary language (google esri history) that you can't use elsewhere.

I will stick to Python (and other languages), .  Besides, python is even beating out the other curly bracket languages in terms of wide spread use.  If you have to do the cloudy map stuff, you may be stuck  but don't use it as a replacement for learning other languages that you can use outside of the "Arc"


... sort of retired...