1

I have these lines of code:

import tkFileDialog, arcpy, arcpy.da, numpy as np, Tkinter
import arcpy.mapping as mapping
fc = tkFileDialog.askopenfilename(filetypes=[('shapefiles','*.shp')],title='Choose a Shapefile')
print 'fc = {0}'.format(fc)
desc = arcpy.Describe(fc)
#Find the number of rows(alternatives) and print it!
number_of_rows = arcpy.GetCount_management(fc)
R = int(number_of_rows.getOutput(0))
print R
#Find the number of columns(criterias) and print it!
C = len(arcpy.ListFields(fc))
print C

It creates a GUI where i can browse and open a shapefile. This shapefile is an ArcMap shapefile with a layer and an attribute table. With this algorithm i get this error:

Traceback (most recent call last):
 File "C:\Users\Th\Desktop\Python Scripting\Σμαραγδάς Αθανάσιος Διπλωματική\Python Codes\Python_Codes\Script1.py", line 8, in <module>
 number_of_rows = arcpy.GetCount_management(fc)
 File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 13613, in GetCount
raise e
ExecuteError: ERROR 000229: Cannot open C:/Users/Th/Desktop/waterways.shp
Failed to execute (GetCount).

How can i solve this? I can access the file with the line below and do the same work with it, but i want to create a GUI so that i can open any file i want to by browsing.

fc = "C:/Users/Th/Desktop/waterways.shp"

I am trying to open the file with the GUI and then use it for any reason i want.But after it prints the directory of the file(as the algorithm demands), i get the error above.

asked Jun 23, 2016 at 13:45
14
  • 1
    Does it work when you manually add it? Commented Jun 23, 2016 at 21:21
  • Yes it does work perfectly. @JamesLeversha Commented Jun 23, 2016 at 21:22
  • 1
    I have worked with tkFileDialog and did not have a problem. What does the print 'fc = {0}'.format(fc) output? Commented Jun 24, 2016 at 3:49
  • Also do a print desc after desc = arcpy.Describe(fc) to see if a describe object is getting created. Maybe try and set the workspace variable in the code, arcpy.env.workspace = fc = tkFileDialog.askopenfilename(filetypes=[('shapefiles','*.shp')],title='Choose a Shapefile') Commented Jun 24, 2016 at 7:19
  • fc = {0}'.format(fc) prints the path of fc: fc = C:/Users/Th/Desktop/waterways.shp @BenSNadler Commented Jun 24, 2016 at 8:10

1 Answer 1

1

As commented by @PauloRaposo:

[This m]ight be an Esri bug ... See this on Error 000229, about background processing being enabled: http://support.esri.com/technical-article/000012177. Your code works just fine for me in a Python console using one of my own shapefiles.

answered Oct 29, 2016 at 10:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.