Select to view content in your preferred language

Re: Populate fields using python (cumulative)

5439
44
10-14-2015 05:50 AM
TerryGustafson
Frequent Contributor

Ok I think I’m close but need a little more help.  I have a
table like the one attached.  I’m trying to create a line segment from it
that goes from 22.473 to 27.346 but they are on separate lines.  I need a
python script to calculate the to_measure from OBJECTID 1 equal to the
to_measure from OBJECTID2.  Do you think that is possible?

0 Kudos
44 Replies
TerryGustafson
Frequent Contributor

I’m trying to calculate a field based on another field in a table using python in the field Calculator.

0 Kudos
DarrenWiens2
MVP Honored Contributor

The last line in the error message indicates that the Field Calculator was run in VB mode:

del cursor" VB #

0 Kudos
TerryGustafson
Frequent Contributor

That is my fault I copied the wrong results.. I get an invalid syntax when I select python..

0 Kudos
DarrenWiens2
MVP Honored Contributor

Not sure if it's an error in the error message or your code, but the line ridList.append(row[0]) should be indented twice.

edit: actually, there are several indentation errors, probably just a problem in the error message. Can you post your code so we can see your indentation? Instructions here.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Terry,

The code I provided was written to be run in the python window.  Attached is an example.  Here are the steps to take:

1.  Add the 'sample' table to ArcMap

2.  Open the Python window

3.  Open 'script1.py' in a text editor

4.  Copy the syntax

5.  Paste into the Python window and click Enter a couple of times to execute the code

The 'sample' table should be updated successfully.

TerryGustafson
Frequent Contributor

Ok, that does work, I was trying to run the python code via the Field calculator. Is that possible? The reason I wanted to do that was I’m building a model to run a process and the second to the last step is to populate the to_MEAS so I can create a line segment.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

It may be easier to add the script to the model.  The only thing you would need to change in the script is the 'table' variable.  You would need to set this to the full path to where the table is.  Ex:

table = r"C:\data\sample.dbf"

TerryGustafson
Frequent Contributor

Ok, I’m stuck on what my parameters should be for the “Display Name” and “Data Type”. I’m thinking Display name is “RID” and Data type is numeric? Also the table is actually going to be in memory so will I need to set the table path?

0 Kudos
JakeSkinner
Esri Esteemed Contributor

You actually won't need to set any parameters.  This is only necessary if the python code contains 'arcpy.GetParameterAsText'.  However, I believe you are going to have to export the table from IN MEMORY to disk.  Then you can update the script to this path.

TerryGustafson
Frequent Contributor

So I’m an idiot. I tried finding information on exporting from memory and can’t seem to find anything on it. This page talks about in-memory but nothing about exporting from it.

http://resources.arcgis.com/en/help/main/10.1/index.html#//002w0000005s000000

I also was looking at this but it seems to be for input of .csv or .txt.

http://resources.arcgis.com/en/help/main/10.1/index.html#//001200000027000000

I have you done an export like this?

0 Kudos