Last week I did a Quick-Fire Tips & Tricks session on SmartText.
If you didn't attend, you can still watch the recorded session here:
https://event.on24.com/eventRegistration/EventLobbyServlet?target=reg20.jsp&referrer=https%3A%2F%2Fwcc.on24.com%2Fwebcast%2Fgroupregistration%2F1780214&eventid=1780214&sessionid=1&key=BE94C9CF0D4D09531DEBF53DE51CD4C5®Tag=316181&sourcepage=register&cid=Social_Global_Software_MapInfo_N/A_Registrations_28082018
I did cover a number of examples so I thought it would be useful to also share the syntax of these samples here in writing.
SmartText Aliases
Let's start with the SmartText aliases. As I said in the webinar, these are stored in a dedicated file. This file will be created the first time, MapInfo Pro comes across an Alias in a layout window that it needs to look-up to find the MapBasic expression or string to substitute the alias with.
The file, SmartTextAliases.xml, is located here, once it has been created: %appdata%\MapInfo\MapInfo\Professional\1700
As you can see in the image below, it holds a list of aliases and their matching fixed string or MapBasic expression.
See Attachment
You can add your own additional aliases if you want to. And you should of course change some of the fixed values to match your name and organisation.
Creating a SmartText in the Layout
There is two ways to create SmartText in the Layout:
- Use an Alias from the SmartTextAliases.xml file
- Enter any MapBasic expression
Alias
You create a SmartText using an Alias by writing the Alias Name inside ${}. So to use the Author alias from the file above, you'll have to write: ${Author}.
When you edit the text, you'll see the SmartText "expression". When you skip the edit mode, you'll will see the resulting string, in this specific case my name, "Peter Horsbøll Møller"
See Attachment
Using the Aliases is quite simple once you get familiar with the available aliases.
MapBasic expressions
You create a SmartText using a MapBasic expression by writing the expression inside $mb{}. So to use the Time(24) expression, you'll have to write: $mb{Time(24)}.
And similar to aliases, you only see the SmartText expression when you edit the text. Otherwise you'll see the resulting string.
See Attachment
And as the example above shows, you can easily combine fixed text with the SmartText elements.
Some other SmartText samples
During the webinar, I gave a few other examples of SmartTexts that could prove useful, especially in Layout Template so that for example the header information is populated more or less automatically.
If you want to use the MapBasic expression directly in the layout which you can, remember to wrap them in this text: $mb{}.
Map Title
I had created a SmartText alias that referred to the title of the Map in a specific frame. The MapBasic expressional of this SmartText is:
WindowInfo(LayoutItemWinID(CurContext(1), "Map-1", 1), 1)
And the Alias in the SmartTextAliases file looks like this:
<Alias name="TitleOfMap-1" description="The window name of the map in the frame named Map-1.">WindowInfo(LayoutItemWinID(CurContext(1), "Map-1", 1), 1)</Alias>
Notice that it refers to the map in the frame called Map-1. This means that you need to make sure that you have named you frame with the map, Map-1. You can do this via the Frame Properties dialog.
See Attachment
Current Workspace
Another useful SmartText was the name of the current workspace. This could be used to easily locate the workspace used to generate the output (paper map or PDF document).
The MapBasic expression is:
GetCurrentWorkspacePath$()
And the SmartText alias in the SmartTextAliases file looks like:
<Alias name="CurWorkspace" description="Current workspace path and file name.">GetCurrentWorkspacePath$()</Alias>
Map Coordinate System Name
You can also create an expression that will show the name of the coordinate system of a map in a specific frame. The frame is here called Map-1.
The MapBasic expression looks like this:
MapperInfo(LayoutItemWinID(CurContext(1), "Map-1", 1), 18)
And the line for the SmartTextAliases file:
<Alias name="CoordsysOfMap-1" description="The coordsys name of the map in the frame named Map-1.">MapperInfo(LayoutItemWinID(CurContext(1), "Map-1", 1), 18)</Alias>
See Attachment
Using custom MapBasic functions
I ended the webinar with showing you have you could use custom MapBasic functions in a running MapBasic application. In my example I was using one of the functions in the WindowHelper x64 tool. The function is called MAPHGetCoordinate.
It takes two parameters:
- The ID of the Map window to get the coordinate from
- A string ID specifying which coordinate to return, center x/Y, minimum X/Y or maximum XY. The IDs are CENTX, CENTY, MINX, MINY, MAXX, and MAXY.
The SmartText expression will currently look like this:
Center: $mb{FormatNumber$(Exec("WindowHelper.mbx", "MAPHGetCoordinate", LayoutItemWinID(CurContext(1), "Map-1", 1), "CENTX"))} | $mb{FormatNumber$(Exec("WindowHelper.mbx", "MAPHGetCoordinate", LayoutItemWinID(CurContext(1), "Map-1", 1), "CENTY"))}
See Attachment
When we release MapInfo Pro 17.0.1 and the WindowHelper gets updated, the expression will be shortened to this:
Center: $mb{FormatNumber$( MAPHGetCoordinate( LayoutItemWinID( CurContext(1), "Map-1", 1), "CENTX")} | $mb{FormatNumber$( MAPHGetCoordinate(LayoutItemWinID( CurContext(1), "Map-1", 1), "CENTY")}
I hope you have found this helpful. I have included my current SmartTextAliases.xml below in case you want to take advantage of some of my aliases.
Do let us know some good examples of how you are using the SmartText feature.