# file_open.py import Tkinter import tkFileDialog import sys # Get command line arguments args = sys.argv args_len = len(args) # Create parent window and hide it from view root = Tkinter.Tk() root.withdraw() # Generate dialog options options = {} options['parent'] = root if args_len == 2: options['title'] = args[1] elif args_len == 3: options['title'] = args[1] options['initialdir'] = args[2] options['multiple'] = False options['filetypes'] = [('Special file','*.special'),('All files','*')] # Show dialog file_path = tkFileDialog.askopenfilename(**options) # Destroy parent window root.destroy() # Print result print file_path
import arcpy import os from subprocess import Popen, PIPE def open_file_dialog(dialog_title, default_dir=None): file_open = "file_open.py" file_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), file_open) file_arg = [file_path, dialog_title] if default_dir is not None: file_arg.append(default_dir) proc = Popen(file_arg, shell=True, stdout=PIPE, bufsize=1) stdoutdata, stderrdata = proc.communicate() proc.terminate() return stdoutdata.strip() file_path = open_file_dialog("Open File") if arcpy.Exists(file_path): pass
But will Tkinter be packaged with the add-in when I distribute it? I distribute my add-ins to other people and I don't want them to have to install additional libraries/interfaces such as Tkinter (and in some cases they aren't allowed to).
Is there a way to use arcpy parameter like you would in a python toolbox?
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.