Batch processing of tables

17 views
Skip to first unread message

Evgeny Kleiman

unread,
Oct 30, 2025, 8:02:23 AM (3 days ago) Oct 30
to MapInfo-L
Hello,
I have a program for processing a list of MapInfo tables. The program is written in C# and calls some commands from MapBasic. In each table of the list 2 fields added and filled according some rules. The program works against MapInfo 2019 or 2023. The program works valid in one computer and shows an error message on the other one. Below I give a scheme of the program.
   It has 2 input parameters:
  - fullPathToCatalog: path to  a table with 2 fields:name of a table from the tables list and name of a field
   - tablesDir - path to directory containing the table that should be processed
 
   public void Main()
        {
            miApp.Do($"Open Table \"{fullPathToCatalog}\" As Targets");            
            ProcessTables();            
            miApp.Do("Close All");
        }

   private void ProcessTables()
        {            
            miApp.Do("Fetch First From Targets");
            string previousTableName = string.Empty;
            while (!miApp.Eval("EOT(Targets)").ToString().Equals("T"))
            {
                string tableName = miApp.Eval("Targets.TableName").ToString();
                string fieldName = miApp.Eval("Targets.FieldName").ToString();
                string sourceTablePath = tablesDir + tableName + ".tab";

                bool isOpened = true;
                while (isOpened)                {
                    if(previousTableName==string.Empty)
                    {
                        previousTableName = tableName;
                        break;
                    }
                    isOpened = EnsureTableNotOpen(previousTableName);
                    if (!isOpened)
                    {
                        previousTableName = tableName;
                        break;
                    }
                    else
                        System.Threading.Thread.Sleep(500); // Brief pause
                }
                ProcessSingleTable(sourceTablePath, tableName, fieldName);

                // Move to next target
                miApp.Do("Fetch Next From Targets");
            }
        }
      private bool EnsureTableNotOpen(string tableName)
        {
            try
            {
                // Try to get list of open tables
                string tableList = miApp.Eval("NumTables()").ToString();
                int tableCount = int.Parse(tableList);
                for (int i = 1; i <= tableCount; i++)
                {
                    string openTableName = miApp.Eval($"TableInfo({i}, TAB_INFO_NAME)").ToString();
                    if (openTableName.Equals(tableName, StringComparison.OrdinalIgnoreCase))
                    {                        
                        System.Threading.Thread.Sleep(500); // Brief pause
                        return true;
                    }
                }
            }
            catch
            {
                // If we can't check, assume it's not open or we can't close it
            }
            return false;
        }

----------------------------------
In procedure ProcessSingleTable where current table is edited on some table (say, tableX) I get a message:
   "Error processing table tableX. Cannot access file tableX.TMA. Cannot perform edit. Someone else currently editing this table"
So I need recommendations how to organize this processing to avoid this error

Peter Horsbøll Møller

unread,
Oct 31, 2025, 8:39:21 AM (2 days ago) Oct 31
to mapi...@googlegroups.com
Hey Evgeny

How do you initiate the variable miApp?

Sometimes this fails because the path to MapInfo Pro hasn't been registered correctly on the computer.

Peter

Peter Horsbøll Møller
Principal Sales Engineer - Distinguished Engineer

 


From: mapi...@googlegroups.com <mapi...@googlegroups.com> on behalf of Evgeny Kleiman <evgeny...@gmail.com>
Sent: Thursday, October 30, 2025 13:02
To: MapInfo-L <mapi...@googlegroups.com>
Subject: [MI-L] Batch processing of tables

This message originated Externally. Use proper judgement and caution with attachments, links, or responses.

--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mapinfo-l/5fcfca14-8b1a-4d8d-94cd-ff6ef16d0e20n%40googlegroups.com.

Evgeny Kleiman

unread,
Oct 31, 2025, 10:47:07 AM (2 days ago) Oct 31
to MapInfo-L
Hello, Peter,
In my code I have:
...
using MapInfo;
...
public class ClearAndReverseProcessor
private string tablesDir;
        private string fullPathToCatalog;
        private MapInfoApplication miApp = null;
       
        public ClearAndReverseProcessor(string fullPathToCatalog, string tablesDir)
        {
            miApp = new MapInfoApplication();
            this.tablesDir = tablesDir;
            this.fullPathToCatalog = fullPathToCatalog;
        }
Reply all
Reply to author
Forward
0 new messages