Modelbuilder and Field calculator for Fields at a parameter table

356
2
03-25-2018 02:36 AM
RanaElKady
New Contributor

I have an Excel sheet enter it to model builder as a parameter and at next steps i need to create an expression for the fields inside the table and add the results to another field. The problem is the fields not exist to select for expression at field calculator.

So is there any way to solve this problem and how could i write ^ inside expression. I have Arc GIS 10.5.

I still new in python programming so,I tried to see some python code from the available codes  but it give me an error Invalid field..

I wish to know what is the problem inside the code

Table name: #it will be parameter

Fields at table need to enter at expression: Geco, Par, kela (All numbers i consider all as float)

The new field for the results is MM

The code i tried with is:

Geco = arcpy.GetParameterAsFloat()

Par = arcpy.GetParameterAsFloat()

kela = arcpy.GetParameterAsFloat()

Geco_new = '!'+Geco+'!'

Par_new = '!'+Par+'!'

kela_new = '!'+kela+'!'

arcpy.CalculateField_management(outputfc, percentfield, '('+Geco_new+'*(2/'+Par_new+')^'+kela_new+'))', "PYTHON") So, please need your help and i appreciate that

0 Kudos
2 Replies
DanPatterson_Retired
MVP Esteemed Contributor

Your python IDE should have raised a number of errors

  1. GetParameterAsFloat  is not an arcpy method perhaps  http://pro.arcgis.com/en/pro-app/arcpy/functions/getparameterastext.htm but you have to provide parameter numbers
  2. Geco_new = '!'+Geco+'!'
    Traceback (most recent call last):
      File "<ipython-input-1-80b166027750>", line 1, in <module>
        Geco_new = '!'+Geco+'!'
    NameError: name 'Geco' is not defined
    Your string concatenation is wrong since Geco doesn't exist as a variable.  Perhaps you meant Geco_new = '!Geco!'

You report any and all error messages when trying to get help with code samples.

Madanbhurati
New Contributor III

Hi,

First Parameter should be Table and For second parameter, You can use Obtain From Parameter property as Excel Sheet. Please review attached snapshot for details.