I have a couple simple scripts trying to iterate processes over directories. They work perfectly fine from the Python Console within MapInfo, however I cannot get them to run properly when called from a tool button. What extra steps or details are needed to get this working?
import os
from os.path import abspath, join
import tkinter as tk
from tkinter import filedialog
import traceback
from MapInfo.Types.Data import *
try:
root = tk.Tk()
root.withdraw()
dir_path = filedialog.askdirectory(title="Select a Folder")
for file in os.listdir(dir_path):
if file.endswith(".TAB"):
tablePath = join(dir_path, file)
pro.Catalog.OpenTable(tablePath)
tabName = pro.Catalog.Tables[pro.Catalog.Tables.Count-1].Alias
do("Pack Table {} Data".format(tabName))
pro.Catalog.CloseAllTables()
except Exception:
traceback.print_exc()
The call to the script is just as follows:
Sub Directory_Pack()
Run Program """C:\Program Files\MapInfo\Professional\Python310\python.exe"" ""C:\LM_Toolbox_2.0\Python\Directory_Pack.py"""
End Sub
------------------------------
Brandon Shepherd
Knowledge Community Shared Account
Shelton CT
------------------------------