select feature class with checkbox arcpy

1500
4
Jump to solution
09-04-2017 01:03 PM
leandrofernandes
New Contributor II

How to select feature class with checkbox arcpy ?

0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

Leandro,

If you are running this tool from inside ArcGIS Desktop or Pro you can take advantage of the ArcGIS geoprocessing setup, which saves you a LOT (A LOT) of effort, and the users of your tool see the tool interface they are used to with other ArcGIS tools.  The examples in the help are for that environment, not the one you are cobbling together using TkInter.  Don't know if you're going to get a lot of help with the code using your alternative approach, which I don't personally recommend.

You can generate a pick list in either environment by getting a list of names using arcpy.ListFeatureClasses() and loading them into a list of strings, which in TkInter you'd load into an object in your custom form (you're outside my knowledge base), or if using the ArcGIS geoprocessing environment into a string parameter with a filter listing the filename strings.

If you want to post code, recommend using geonet formatting: https://community.esri.com/people/curtvprice/blog/2014/09/25/posting-code-blocks-in-the-new-geonet?s...

View solution in original post

0 Kudos
4 Replies
curtvprice
MVP Esteemed Contributor

If you mean picklist, not checkbox, this is done in the tool parameter properties(.tbx) or in Python code (.pyt) using a filter. Layer parameters look at the currently open ArcMap session to create a list of map layers you can pick from.

Setting script tool parameters—Help | ArcGIS Desktop 

Defining parameters in a Python toolbox—Help | ArcGIS Desktop 

leandrofernandes
New Contributor II

Sorry, I started with arcpy yesterday and I do not understand.

I have a .gdb and I would like to select some feature class to load in SQL Server, but not all.


import arcpy
from Tkinter import *

root = Tk()
features = []

def var_states():
print 'Upload data SQL ?????'

arcpy.env.workspace = "D:\GIS\Treinamento\deletar.gdb"

datasets = arcpy.ListDatasets(feature_type='feature')
datasets = [''] + datasets if datasets is not None else []
i = 1

Label(root, text="Select Features Class: ").grid(row=0, sticky=W)

for ds in datasets:
for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
var = IntVar()
desc = arcpy.Describe(fc)
chk = Checkbutton(root, text=desc.name, variable=var).grid(row=i, padx = 20 , sticky=W)
features.append(fc)
i = i + 1

Label(root, text="").grid(row=i, sticky=W)
i = i+1
button = Button(root, text='OK', command=var_states)
button.grid(row=i+1, sticky=W)
button.place(relx=0.5, rely=0.9, anchor=CENTER)
i = i+1

w = 350
h = i * 22
ws = root.winfo_screenwidth() # width of the screen
hs = root.winfo_screenheight() # height of the screen
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
root.geometry('%dx%d+%d+%d' % (w, h, x, y))

root.mainloop()

#print map((lambda var: var.get()), states)


I do not know how to find the features class chosen

Does anyone have an example that I can use?

0 Kudos
curtvprice
MVP Esteemed Contributor

Leandro,

If you are running this tool from inside ArcGIS Desktop or Pro you can take advantage of the ArcGIS geoprocessing setup, which saves you a LOT (A LOT) of effort, and the users of your tool see the tool interface they are used to with other ArcGIS tools.  The examples in the help are for that environment, not the one you are cobbling together using TkInter.  Don't know if you're going to get a lot of help with the code using your alternative approach, which I don't personally recommend.

You can generate a pick list in either environment by getting a list of names using arcpy.ListFeatureClasses() and loading them into a list of strings, which in TkInter you'd load into an object in your custom form (you're outside my knowledge base), or if using the ArcGIS geoprocessing environment into a string parameter with a filter listing the filename strings.

If you want to post code, recommend using geonet formatting: https://community.esri.com/people/curtvprice/blog/2014/09/25/posting-code-blocks-in-the-new-geonet?s...

0 Kudos
leandrofernandes
New Contributor II

Thanks