Select to view content in your preferred language

Add a value automatically in the field

3167
11
11-20-2017 08:07 AM
KhamisBaroud
Emerging Contributor

I have a layer with 3 fields (1. Building number, 2. Street number, 3. Field combining building number and street number) The last field was calculated using the Field Calculator tool.
  But the problem is when you add a new record or a new building I will need to repeat this process Field Calculator
Is there a way to add data in field number 3 automatically without using Field Calculator to combine the value of the building number and the street when a new building is added?

I need to know if there is a script to do so.

thanks beforehand

0 Kudos
11 Replies
DanPatterson_Retired
MVP Emeritus

Perhaps in arcobjects.  What is the problem with doing the data entry first, then the calculations later?

0 Kudos
KhamisBaroud
Emerging Contributor

I need to know if there is a script to do so

(Python or VB Code)

0 Kudos
JamesMacKay3
Frequent Contributor

Using ArcObjects and VB.NET you could build an application extension that would listen to editor events, or a geodatabase class extension that listens to object class events.  Neither are very simple tasks however, and there are drawbacks to each, particularly class extensions (anyone accessing the data must have the extension's DLL installed, for example).

Editor Events doc:  ArcObjects 10 .NET SDK Help 

Class Extension doc: ArcObjects 10 .NET SDK Help 

So...  It's possible, but I wouldn't recommend it unless you have a very compelling reason not to just use the field calculator.

JoshuaBixby
MVP Esteemed Contributor

It might be worth looking into Attribute Assistant | ArcGIS Solutions  if you haven't already.

XanderBakker
Esri Esteemed Contributor

And in Pro at 2.1 a new thing as part of the ArcGIS Utility Network Management extension will be introduced called Attribute Rules. I believe it will be available for users without the ArcGIS Utility Network Management extension too (not completely sure though) and it will use Arcade expressions and can do a lot more than just populate a field based on other attributes. It will not be available for ArcMap.

JamesCrandall
MVP Frequent Contributor

You could probably just create a python add-in extension and implement the openDocument event to fire.  I'd check the TOC if the layer you want to process is loaded and if not, load it then process it as desired.

http://desktop.arcgis.com/en/arcmap/latest/analyze/python-addins/creating-an-add-in-application-exte...

0 Kudos
DanPatterson_Retired
MVP Emeritus

So from the above suggestions, you have many options.  How important is it that this be an integral part of your workflow?

0 Kudos
AmirBar-Maor
Esri Regular Contributor

Use Attribute Rules in ArcGIS Pro to add a Calculation rule using the Arcade scripting language.

To add a new Calculation rule use the geoprocessing tool 'Add Attribute Rule'.

You can learn more about Arcade here and find useful examples of calculation fields here.

For your example it should look something like this:

$feature.Building_number + $feature.Street_number

You can define the rule to run when you Insert and modify the feature.

More string manipulation can be found here

If you are using ArcMap or File geodatabase you can use the Attribute Assistant Add-In from Attribute Assistant | ArcGIS Solutions 

JoeBorgione
MVP Emeritus

Use Attribute Rules in ArcGIS Pro to add a Calculation rule using the Arcade scripting language.

Just remember that:

Attribute rules are only supported on enterprise geodatabase datasets. 

and

Once you have added attribute rules to a dataset, the minimum client version for the dataset is ArcGIS Pro 2.1. This means that the dataset will no longer be available for use in ArcGIS Desktop.

(Add Attribute Rule—Data Management toolbox | ArcGIS Desktop )

https://community.esri.com/ideas/15235 

That should just about do it....