[GIS] Finding text object variable names in MapInfo/MapBasic

mapbasicmapinfo

In MapBasic you can create a text object in a layout window by using the "Create text" statement. You can also use the same statement to update this object.

I am working on a tool that creates several plans by repeatedly exporting a layout window as an image file. Between each export I would like to update the text in the layout window to indicate the reference number of the site.

How do I go about finding the object's variable name?

Best Answer

I have done this but as far as I know you have to select the text object using the text that is in that object. Here is some example code which finds an object by looking for the the text in the variable searchText:

Dim searchText, newText as String
Dim oLayout As Object
strLayWinName = WindowInfo(WindowID(FrontWindow()), WIN_INFO_TABLE)
searchText = "@01"
newText = "Text I want to add to the text object"

select * from strLayWinName where val(str$(objectinfo(object,1))) = 10 into strLaySel noselect
select * from strLaySel where Left$(str$(objectinfo(object,3)),Len(searchText)) = searchText into strLayObjSel

oLayout = strLayObjSel.object ' put the selected object into an object variable called oLayout
alter object oLayout info 3, searchText + " " + newText ' where new text is a string variable of your new text
update selection set object = oLayout

To expand on this, the way I use this code is to create a text object on a layout with some standard text at the front of it (for example I place an @ symbol and a number, so on the layout the text would read "@01 Text I want in the text object"). Then I place a white rectangle object on the layout over the "@01" part of the string to hide this.

When using the above code, the searchText variable is set to "@01" and the 7th line of code finds the text object where the first 3 characters are equal to "@01". Once you have this object, it sets its new value to the searchText plus whatever you want to change the remainder of the text object to which you set in the newText variable. If you give all of the text objects on the layout different numbers, then you can refer to them uniquely by checking the first 3 characters of the string. I have edited the code a little to make it clearer.

I know its not a particularly pretty way to do it, but it does work well.

Related Question