Select to view content in your preferred language

ERROR 999999: Error executing function - Adding Field in a FOR statement

1557
1
06-11-2012 02:44 PM
MariellaCarbajal
Emerging Contributor
Hello everybody
I was trying to start a code to analyze some measure points in different scales and exponents, when I found an extrange error and I don't understand why it happen.
Ther error says:.

ERROR 999999: Error executing function.
Failed to execute (AddField).

And it only happen when I put AddField function into a FOR statement and not out of it.
I'd realy like to know why it is, any help will welcome!


import arcpy
from arcpy import env
from arcpy.sa import *
import math
from math import sqrt
import numpy
from numpy import *
import shapefile

try:
   
    # Check out any necessary licenses
    arcpy.CheckOutExtension("spatial")


    env.workspace = "D:/Users/"
    inFeatures=["WS.shp","malla.shp"]
    outPoints="WSTT.shp"
    Malla="malla.shp"
    Calcs="calcs.shp"
    arcpy.Intersect_analysis(inFeatures, outPoints, "", "", "point")

    arcpy.Copy_management(Malla, Calcs, "")
    arcpy.JoinField_management(Calcs, "FID", outPoints, "FID_malla_", "Pp")
    arcpy.Delete_management(outPoints)

    sf = shapefile.Reader(Calcs)
    fields=sf.fields
    records = sf.records()
       
    ppp=[]
    lg=len(records)-1

    for i in range(0,lg):
        pp=records[2]
        ppp.append(pp)

    ppp=numpy.array(ppp)
    Nt=sum(ppp)
    print Nt
    for L in range(0,4):
        sc=int(2**L)
        scn="sc"+str(sc)
        Ppsc="Ppsc"+str(sc)
        Pi="Pi_"+str(sc)

            ########### Ni(L) #################
        arcpy.AddField_management(Calcs, Ppsc, "FLOAT", "10", "6", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
        arcpy.CalculateField_management(Calcs, Ppsc, '!Pp!', "PYTHON","")    

        arcpy.AddField_management(Calcs, scn, "text", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")       
        arcpy.CalculateField_management(Calcs, scn, 'str(int(math.ceil(float(!x!)/sc)))+","+str(int(math.ceil(float(!y!)/sc)))', "PYTHON","")
  
        outDissolve="Pp_sc"+str(sc)+".shp"
        dissolveField = [scn]
        statistics=Ppsc+" SUM"
        arcpy.Dissolve_management(Calcs, outDissolve, dissolveField, statistics,"MULTI_PART", "DISSOLVE_LINES") 
       
        print L


except Exception, e:
    print arcpy.GetMessages()


Thanks in advance

Mariella
Tags (2)
0 Kudos
1 Reply
markdenil
Frequent Contributor
Please use code tags.
The '#' button in the repy editor (middle row, far right group, left button) will insert the automatically,
or you can type them.
openCodeTag = "[" + "CODE" + "]"
closeCodeTag = "[" + "/CODE" + "]"

openCodeTag 
your code here
   preserving indentation
Making code readable and less Obscure(somewhat)
closeCodeTag 
0 Kudos