Name and path of current workspace in Mapbasic

452 views
Skip to first unread message

Aladar

unread,
Jan 8, 2009, 6:17:53 PM1/8/09
to MapInfo-L
Hi everyone,

I'd like to access from mapbasic the information name and path of the
latest saved workspace. Exactly like when you use File/Save workspace
Cnrtl+K you can see the file name.
I'd like to put this information using mbx as note on footer in Layout
window for easier identification of workspaces for later changes.

I couldn't find anything in mapbasic reference document.

Thanks and happy new year to everyone!

Aladar



Peter Horsbøll Møller

unread,
Jan 9, 2009, 2:46:42 AM1/9/09
to mapi...@googlegroups.com
Aladar,
 
You can achieve this by "attaching" your own MapBasic procedure to the menu item Save Workspace.
When you do so you can store the name of the latest workspace in a modular variable.
 
Have a look at this example:
 
'***************************************************************
Include "MapBasic.def"
Include "Menu.def"
 
Declare Sub Main
Declare Sub EndProgram
Declare Sub EndHandler
Declare Sub MENUSaveWorkspace
 
'**The modular variable to hold the name of the latest saved workspace
Dim msCurrentWorkspace As String
'----------------------------
Sub Main
  '**Setting Save Workspace to use my own procedure for this
  Alter Menu Item M_FILE_SAVE_WORKSPACE
    Calling MENUSaveWorkspace
End Sub
'----------------------------
Sub EndHandler
  '**Undoing my change to avoid breaking MapInfo when my application ends
  Alter Menu Item MENUSaveWorkspace
    Calling M_FILE_SAVE_WORKSPACE
End Sub
'----------------------------
Sub MENUSaveWorkspace
Dim sPath, sFile As String
 
  If msCurrentWorkspace <> "" Then
    sPath = PathToDirectory$(msCurrentWorkspace)
    sFile = PathToFileName$(msCurrentWorkspace)
  End If
  '**Asking the user to pick a place and file for the workspace
  sFile = FileSaveAsDlg(sPath, sFile, "WOR", "Save current workspace as ... (Custom)")
  If sFile = "" Then
    Exit Sub
  End If
  '**Storing the latest saved workspace in a modular variable
  msCurrentWorkspace = sFile
  '**Saving the current workspace
  Run Command "Save Workspace As " & Chr$(34) & msCurrentWorkspace & Chr$(34)
 
End Sub
'***************************************************************
 
You can extend this so that you also create your own procedure for opening workspaces and so catching that name as well.
But I doubt you can catch everything. The user could open a workspace from the list of most recent files, and that would be stored.
And the Open dialog allows users to open any type of files, including workspace. That dialog could be tricky to create on your own.
 
Someone showed that you could look in the list of mos recent files and in that way get the name of the latest workspace.
Have a look at this thread:
 
Peter Horsbøll Møller
Pitney Bowes Business Insight - MapInfo
2009/1/9 Aladar <slavo...@gmail.com>

Aladar

unread,
Jan 11, 2009, 5:26:04 PM1/11/09
to MapInfo-L
Thanks Peter,

Nice sneaky solution :) I didn't think that way.

cheers,
Aladar
Reply all
Reply to author
Forward
0 new messages