Original Message:
Sent: 06-19-2025 05:03
From: Peter Møller
Subject: Python from console vs called from Ribbon
Hey Brandon
A Python script is considered an application or a script in MapInfo Pro.
Can you try running the Python file using one of these statements:
Sub Directory_Pack() Run Application "C:\LM_Toolbox_2.0\Python\Directory_Pack.py"End Sub
or
Sub Directory_Pack() Run Script "C:\LM_Toolbox_2.0\Python\Directory_Pack.py"End Sub
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
Original Message:
Sent: 06-18-2025 13:33
From: Brandon Shepherd
Subject: Python from console vs called from Ribbon
To be clear, we have other tools that work successfully using this call method, but none that attempt to use the MapInfo Pro Extensibility to use internal features. I believe the issue may stem from the MapInfo.Types Import outside of the Python Console.
Our success with Python Extensibility has been very limited. We want to create python add-ins down the line that do not require accompanying map basic scripts, but are so far hung up on the method.
------------------------------
Brandon Shepherd
Knowledge Community Shared Account
Shelton CT
Original Message:
Sent: 06-18-2025 12:51
From: Brandon Shepherd
Subject: Python from console vs called from Ribbon
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 osfrom os.path import abspath, joinimport tkinter as tkfrom tkinter import filedialogimport tracebackfrom 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
------------------------------