Some enhancements have been added to MapBasic to make Smart Text more powerful and easier to use. These include new functions CurContext() and LayoutItemWinID(), and enhancements to the LayoutItemInfo() and LayoutPageItemInfo() functions.
Using the CurContext() function
Smart text in a text frame often needs to be able to refer to the current layout window, the current page that the frame is on, or the frame's current ID in order to use various MapBasic functions. CurContext provides this context.For example, the following can be used to display the Name property of a text frame:
$mb{LayoutItemInfo(CurContext(1), CurContext(3), 14}
CurContext(1) returns the current Layout Window identifier which is then passed as the 1st argument to LayoutItemInfo. CurContext(3) returns the frame’s current ID which is passed as the 2nd argument. CurContext is valid only within a Smart Text expression in a text frame, and is used to provide the current context to other MapBasic functions such as MapperInfo, etc. For more information and examples see the MapBasic Reference for the CurContext function.
Using LayoutItemWinID(), LayoutItemInfo() and LayoutPageItemInfo() functions
The LayoutItemWinID() function can be used in any MapBasic context but was added as a way to make it easier to get the Window identifier of a Map, Browser, or Legend Designer frame on a Layout page.
For example,
LayoutItemWinID(CurContext(1), "Main Map", 1)
Will search the entire Layout document for a Map frame named “Main Map” and return its Window identifier. This in turn can be passed to a WindowInfo or MapperInfo function to get related information about that Map window.
In addition, both LayoutItemInfo and LayoutPageItemInfo can now take a frame name as an argument instead of a numeric frame ID.
LayoutItemInfo(CurContext(1), "Company Logo", 12)
Examples of Smart Text using Frame Names
The following screen shot shows two examples of Layout Smart Text using frame names to link text to map information.
$mb{WindowInfo(LayoutItemWinID(CurContext(1), "Main Map", 1), 1)}
But
could also be done using the additional change to
LayoutItemInfo:$mb{WindowInfo(LayoutItemInfo(CurContext(1), "Main Map", 5), 1)}
The
text showing "Scale 1 in = 11.0673 mi" is using Smart Text
expression:Scale 1 in = $mb{MapperInfo(LayoutItemInfo(CurContext(1), "Main Map", 5), 2)} $mb{MapperInfo(LayoutItemInfo(CurContext(1), "Main Map", 5), 12)}
But
could also be done using new
LayoutItemWinID:Scale 1 in = $mb{MapperInfo(LayoutItemWinID(CurContext(1), "Main Map", 1), 2)} $mb{MapperInfo(LayoutItemWinID(CurContext(1), "Main Map", 1), 12)}