Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
Thanks for that. I've ended up using a mix of your code and Peter's code from here: groups.google.com/group/mapinfo-l/browse_thread/thread/…. Peter's idea of storing the RowID makes changing the text repeatedly a bit easier. Saves searching through tables each time. Others may have an issue of the RowIds changing if other objects are added/removed from the layout but for my purposes this is not an issue. –  Mr_Chimp Jun 29 '11 at 10:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.