Debugging a Python Add-in for MapInfo Pro - MapInfo_Pro - 2023

MapInfo Pro Help

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapInfo Pro
Version
2023
Language
English
Product name
MapInfo Pro
Title
MapInfo Pro Help
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:39:16.995549
  1. In VSCODE, open the folder of your python add-in or any python add-in sample (for example, .\SAMPLES\RIBBONINTERFACE\Python\HelloPython).
  2. Compile the add-in *.mbx using MapBasic IDE or Notepad++, etc.
  3. In your python add-in source code, add the following lines:
    import ptvsd 
    # Allow other computers to attach to ptvsd default port.
    ptvsd.enable_attach()
    # Pause the program until a remote debugger is attached
    ptvsd.wait_for_attach()
  4. Run the add-in MBX in MapInfo Pro v17.0.3 or above. Now once MBX is run in MapInfo Pro, you will notice a wait cursor denoting that the process in waiting for some debugger to attach to it.

  5. Switch to Debug View in VS Code, and select Python: Attach configuration.

  6. Set a breakpoint in the code where you want to start debugging. Setting a single breakpoint on the statement immediately following the ptvsd.wait_for_attach() line may not work. Set at least one other breakpoint on another statement.

  7. Start the VS Code debugger using the modified Python Attach configuration. VS Code should stop on your locally-set breakpoints, allowing you to step through the code, examine variables, and perform all other debugging actions. Expressions that you enter in the Debug Console are run on the remote computer as well.

  8. During remote debugging, the debugging toolbar appears. On this toolbar, the disconnect button (Shift+F5 ) stops the debugger and allows the remote program to run to completion.