0 Replies Latest reply on May 2, 2012 5:40 AM by obiemekus

    Error Message    ERROR 999998: Unexpected Error  Failed to execute

    obiemekus
      Hey guys, i am some how new to python programing.  I created a sript that selects a polygon tile/grid and uses the tile to clip all data feature classes  in the tile.  The cliped data will then beconverted into a dxf and dropped in a folder.  But when I batch the process so it could go over 5 or more grids, it stops at the second grid and gives me this error message.  Any help will be appreciated.  (See code below)


      import sys, arcgisscripting
      gp = arcgisscripting.create()
      gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx")
      gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
      gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")
      gp.overwriteOutput = 1

      #grid feature class
      gridFC = gp.getParameterAsText(0)
      #gdb holding all feature classes to be clipped
      mapNo = gp.getParameterAsText(1)
      inputGDB = gp.getParameterAsText(2)


      #final output folder
      outputFolderRoot = gp.getParameterAsText(3)
      #list of feature classes


      gp.Extent = "1336418.000000 556751.000000 1504418.000000 748751.000000"
      exportNames = ['Building','Contours','Rec','Communication_Towers','Cultural','Rail','Road','Transmission','Vegetation']
      gridCursor = gp.searchCursor(gridFC, "MAPNO = '" + mapNo + "'")
      currentGrid = gridCursor.next()

      scratchGDB = outputFolderRoot + "\\Scratch.gdb"
      if gp.Exists(scratchGDB):
          gp.Delete_management(scratchGDB)
         
      gp.addMessage("Creating scratch database...")
      gp.CreateFileGDB(outputFolderRoot, "Scratch.gdb")

      currentMapNo = currentGrid.MAPNO
      gp.CreateFolder_management(outputFolderRoot, currentMapNo)
      outputFolderName = outputFolderRoot + "\\" + currentMapNo
      whereClause = "MAPNO = '" + currentGrid.MAPNO + "'"
      currentClip = scratchGDB + "\\currentGridClip"

      #create clipped map to use to clip all feature classes
      gp.addMessage("Selecting MAPNO = " + currentMapNo)
      gp.Select_analysis(gridFC, currentClip, whereClause)
      for exportName in exportNames:
          gp.addMessage("Clipping " + exportName + " for MAPNO = " + currentMapNo)
          inputFC = inputGDB + "\\" + exportName
          if gp.Exists(inputFC):   
              inputAnno = inputFC + "_Anno"
              outputClipName = scratchGDB + "\\" + exportName + "_" + currentMapNo
              outputDWGName = outputFolderName + "\\" + exportName + "_" + currentMapNo + ".DWG"
              try:
                  gp.Clip_analysis(inputFC, currentClip, outputClipName)
                  if gp.Exists(outputClipName):
                      if gp.Exists(inputAnno):
                          #include anno if it exists
                          outputClipAnnoName = scratchGDB + "\\" + exportName + "Anno_" + currentMapNo
                          gp.addMessage("Clipping " + exportName + "Anno for MAPNO = " + currentMapNo)
                          gp.Clip_analysis(inputAnno, currentClip, outputClipAnnoName)
                          exportParameter = outputClipName + ';' + outputClipAnnoName
                          gp.addMessage("Converting " + exportName + " to CAD...")
                          gp.ExportCAD_conversion(exportParameter, "DWG_R2000", outputDWGName, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")
                      else:
                          #skip anno
                          gp.addMessage("Converting " + exportName + " to CAD...")
                          gp.ExportCAD_conversion(outputClipName, "DWG_R2000", outputDWGName, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")
              except:
                  gp.addMessage("Clipping of " + exportName + " failed.  Moving on.")

      hydroLine = inputGDB + "\\Hydrology_Line"
      hydroPoly = inputGDB + "\\Hydrology_Poly"
      outputDWGName = outputFolderName + "\\hydro_" + currentMapNo + ".DWG"
      gp.addMessage("Converting hydro to CAD...")   
      if gp.Exists(hydroLine):
          if gp.Exists(hydroPoly):
              #both poly and line exist
              exportParameter = hydroLine + ';' + hydroPoly          
              gp.ExportCAD_conversion(exportParameter, "DWG_R2000", outputDWGName, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")
          else:
              #if line exists but not poly
              gp.ExportCAD_conversion(hydroLine, "DWG_R2000", outputDWGName, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")
      else:
          #line does not exist
          if gp.Exists(hydroPoly):
              #poly exists, but not line
              gp.ExportCAD_conversion(hydroPoly, "DWG_R2000", outputDWGName, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")
             

      gp.Delete_management(scratchGDB)