Jump to content
GMS, SMS, and WMS User Forum

stoyan

Members
  • Content Count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral

About stoyan

  • Rank
    Member
  1. This function reproduces part of the AssignHydroID tool's functionality. It does not take into account individual layers as listed in the LAYERKEYTABLE, as I don't have a need for this. def assignHydroID(apuniqueid, fc, overwrite=False): '''apuniqueid: the location of the apuniqueid table fc: the feature class which needs the HYDROID populated overwrite: True if the existing HydroIDs in the fc should be overwritten Populates the HYDROID in the given fc based on the lastest hydroidid from the apuniqueid table Returns: True if successful False if the table/fc does not exist Throws: exception if the table/fc can not be open for editing/inserting ''' import arcgisscripting gp = arcgisscripting.create(9.3) if not gp.exists(apuniqueid): gp.adderror("APUNIQUEID: %s table does not exist"%apuniqueid) return False if not gp.exists(fc): gp.adderror("%s does not exist"%fc) return False lastid = 0 exists = False #True if a HYDROID entry already exists in the apuniqueid table rows = gp.searchcursor(apuniqueid,"IDNAME = 'HYDROID'") row = rows.next() if row: lastid = row.LASTID exists = True del row, rows rows = gp.updatecursor(fc,"","","HYDROID") row = rows.next() while row: if row.isnull("HYDROID") or overwrite: lastid+=1 row.HYDROID = lastid rows.updaterow(row) row = rows.next() del row, rows if exists: #a HYDROID entry already exists, so simply update the field rows = gp.updatecursor(apuniqueid,"IDNAME = 'HYDROID'") row = rows.next() row.LASTID = lastid rows.updaterow(row) del row, rows else: #need to make a new entry into the table for HYDROID rows = gp.insertcursor(apuniqueid) row = rows.newrow() row.IDNAME = "HYDROID" row.LASTID = str(lastid) rows.insertrow(row) del row, rows gp.addmessage("Populated the HydroID field in %s."%fc) gp.addmessage("The next hydroid would be %s"%lastid) return True
  2. Hi, could someone please help me with the following issue: every time I call AssignHydroID_archydro from a Python script I get the following exception: Traceback (most recent call last): File "<string>", line 244, in run_nodebug File "C:\masterImport.py", line 63, in <module> gp.AssignHydroID_archydro(fc) arcgisscripting.ExecuteError: System.NullReferenceException: Object reference not set to an instance of an object. at ESRI.APWR.ArcHydroGPTools.AHAssignHydroID.Execute(IArray paramvalues, ITrackCancel trackcancel, IGPEnvironmentManager envMgr, IGPMessages message) Failed to execute (AssignHydroID). Here is the relevant part of the Python script: ----------------------------------------------------------------------------------------------------- import arcgisscripting gp = arcgisscripting.create(9.3) gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Arc Hydro Tools.tbx") gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Arc Hydro Groundwater Tools.tbx") ...various variable definitions if gp.exists(gwd): gp.OpenGroundwaterConfig_Groundwater(gwd, gwd_project_name) else: gp.CreateGroundwaterConfig_Groundwater(rasters, gwoutput, gwd_project_name, gwd) if gp.exists(ahd): gp.OpenArcHydroConfig_archydro(ahd, ahd_project_name) else: gp.CreateArcHydroConfig_archydro("Groundwater", rasters, gdb, ahd_project_name, ahd) fc = r"C:\MMM.gdb\Framework\Well" #the fc lives within the fgdb configured in the .ahd and .gwd files gp.AssignHydroID_archydro(fc) #this line throws the exception #gp.AssignHydroID_archydro(fc,"") #these 2 combinations fail too #gp.AssignHydroID_archydro(fc,"OVERWRITE_YES") ----------------------------------------------------------------------------------------------------- I am running AHGW 2.0 on ArcGIS 9.3.1 SP1 (ArcInfo license). The AHGW hardware dongle is plugged in. Some observations: -Running the Assign Hydro ID tool from a model works fine -Trying to call a model, containing the Assign Hydro ID call, from a Python script fails with the same exception as above -Calling Assign Hydro ID from a Python script on a feature class which has already had all HydroIDs populated works fine -In summary: AssignHydroID only fails when called from a Python script and it needs to insert new ids. Could someone please tell me how to get around this problem? I would be very appreciative as calling AssignHydroID_archydro from a script would automate my import process very nicely. Much obliged, Stoyan.
×
×
  • Create New...