Applying field calculator only on selected features

12060
24
12-13-2017 08:40 AM
NavidMoghadam
New Contributor II

In #ArcGISPro 2.0.1 Field calculator applies the value on ALL features and not only SELECTION. The same operation worked perfectly with the same data in the same FGDB in ArcMap.

0 Kudos
24 Replies
DanPatterson_Retired
MVP Emeritus

2.2 two copies, selection in one, field calculation (changing 'hello' to None)

The file is updated even though there is a selection in one

 

0 Kudos
KoryKramer
Esri Community Moderator

Dan, with both tables open side by side like you have them, make sure you have no selection in the table on the left. 

Select only one record in the table on the right.

Open Calculate Field by right-clicking the test field from the table on the left (there is no selection on this table).

With the Calculate Field tool open, NOW switch the input layer to the other table (table on the right where you have a selection).  We think we should now be calculating only the selected record in the table on the right.

Calculate.

What happens?

DanPatterson_Retired
MVP Emeritus

Sorry for the delay

KoryKramer
Esri Community Moderator

Right. So you're seeing what I see and this is the issue that we are aware of.  Both of your layers have the same name.

If the layers are named differently, this isn't an issue.  

WrightKennedy
New Contributor II

I've finally had a chance to look at this again. I think the issue here is confusion about which table is which. The bug, from what I can tell, is that the Calculate Field tool always sets the Input Table default value to the first instance of the feature layer no matter the table used to open the tool. Rather than trusting the default value, if the Input Table value is set to the correct table, the field calculator works as expected on selected fields. When you switched to the "other table," you actually switched to the table from which you opened the tool. See screenshots below:

Figure 1. Right click and open Calculate Field from StatesTest:1. The default Input Table is StatesTest:1.

Table 1

Figure 2. Right click and open Calculate Field from StatesTest:2. The default Input Table is still StatesTest:1

Table 2

Kory, please let me know if there is a separate bug related to the Calculate Field tool and selected features, or if the Calculate Field - Input Table default value is the root of the trouble.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Just as an observation, did you try clicking on the folder beside the drop down arrow and navigate to the featureclass on disk rather than relying on the name that appears on the input line? Assuming that the two files of the same name are in different locations, then the correct file should be selected

0 Kudos
WrightKennedy
New Contributor II

Thanks for the suggestion. Yes, this is specifically for the issue of limiting a field calculation to the selected features in a feature class (the OP's question) when multiple copies of the same feature class are in the map as different layers (my guess at the reason for the OP's issues). Using the file browser to select an absolute path for the Input Table ignores all selections (as expected, and as it worked in ArcMap when calculating a field from ArcToolbox). In ArcMap when you have multiple copies of the same feature class and you calculate a field from the Field Calculator (right click on a field name > Field Calculator), the field calculation only applies to the selected records in the table from which you opened the field calculator (regardless of duplicate layers). ArcGIS Pro is causing problems because when you follow the same steps (right click on field name > Calculate Field), the default Input Table is not necessarily the table and selected records from which the tool was opened, but instead the first instance of that layer name found in the Contents panel (former Table of Contents).

The other very tricky thing I just found is that if you are working from the python line, if you use Send To Python Window (or Copy Python command) from Geoprocessing history, even if the Calculate field ran on the selected features from the correct Input Table (e.g., "StatesTest:2" from above screenshot), the field calculation runs on the first instance of the feature class in the Contents pane and whichever records are selected in that layer, since python doesn't include or allow (that I can tell) the ':2' notation that works in the Calculate Feature tool.

tl;dr Don't have layers with the same names, but if you have to have them, put them in group layers with different names. (you can do even more damage without realizing it if you use Calculate Field when ToC includes different feature classes with the same layer/alias name)

0 Kudos
ReneAubut
Occasional Contributor

Had the same bug (selection not respected with Calculate Field) but not because I had the same layer loaded more than once. On my side, it looks more because it is a Feature Layer from AGOL,created from Survey123. From my experience, Pro has numerous functions that are not supported with these feature layers

0 Kudos
ChristopherHanni
New Contributor II

Is there any development on a simple toggle button for selected or all features? 

ThomasL
Occasional Contributor

We had the same bug (selection not respected with Calculate Field) because of same layer names loaded (fc from a FGDB). 

Kory Kramer Is this a known bug at Esri? 

0 Kudos