-1

This code executes correctly in Python window but fails with

ERROR 000732: Input Table: Dataset JHJ does not exist or is not supported

# Import ArcPy and other required modules
import arcpy
from arcpy import env
import fileinput
import string
import os
env.overwriteOutput = True
filud=file(r"c:\temp\dum.txt","w")     # Open file for debug output
filud.write("Hello \n")
try:
   # Will create shape file fcname.shp
   arcpy.CreateFeatureclass_management(r"C:\temp\TestArcGis\FraFil","JHJ","Polyline")
   filud.write(str(time.time()) + " After create \n")
except Exception as e:
   filud.write(str(time.time()) + "Error: " + e.message + "\n")
try:
   # Add fields for data
   filud.write(str(time.time()) + " Before Addfield " + "JHJ" + "\n")
   arcpy.AddField_management("JHJ","Sbet","TEXT")
except Exception as e:
  print e.message
  filud.write("Error: " + e.message)
filud.close()
4

It works in the python window because JHJ is likely a layer in the map and therefore can be reference in your script as "JHJ". When run outside of Arcmap, you need to tell arcpy where to look. Here are just a few ways you can do this (untested, but it should give you a few ideas):

1)

jhj = arcpy.CreateFeatureclass_management(r"C:\temp\TestArcGis\FraFil","JHJ","Polyline")
......
arcpy.AddField_management(jhj,"Sbet","TEXT")

2)

env.workspace=r"C:\temp\TestArcGis\FraFil"
arcpy.CreateFeatureclass_management(r"C:\temp\TestArcGis\FraFil","JHJ","Polyline")
......
arcpy.AddField_management("JHJ","Sbet","TEXT")

3)

jhj = r"C:\temp\TestArcGis\FraFil\JHJ"
arcpy.CreateFeatureclass_management(*os.path.split(jhj),"Polyline")
......
arcpy.AddField_management(jhj,"Sbet","TEXT")
1

In AddField, provide the full path to JHJ or change your workspace (arcpy.env.workspace) to r"C:\temp\TestArcGis\FraFil" before AddField.

1

Try setting arcpy.env.workspace to your working directory. e.g.,

import arcpy
arcpy.env.workspace = 'c:/temp/testarcgis/frafil'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.