Purpose
Returns Pen, Brush, or other values describing a graphical object. You can call this function from the MapBasic window in MapInfo Pro.
Syntax
ObjectInfo( object, attribute )
object is an Object expression.
attribute is an integer code specifying which type of information should be returned.
Return Value
SmallInt, integer, string, float, Pen, Brush, Symbol, or Font, depending on the attribute parameter.
OBJ_INFO_NPOLYGONS (21) is an integer that indicates the number of polygons (in the case of a region) or sections (in the case of a polyline) which make up an object.
OBJ_INFO_NPOLYGONS+N (21) is an integer that indicates the number of nodes in the Nth polygon of a region or the Nth section of a polyline.
Description
The ObjectInfo() function returns general information about one aspect of a graphical object. The first parameter should be an object value (for example, the name of an Object variable, or a table expression of the form tablename.obj).
Each object has several attributes. For example, each object has a "type" attribute, identifying whether the object is a point, a line, or a region, etc. Most types of objects have Pen and/or Brush attributes, which dictate the object's appearance. The ObjectInfo() function returns one attribute of the specified object. Which attribute is returned depends on the value used in the attribute parameter. Thus, if you need to find out several pieces of information about an object, you will need to call ObjectInfo() a number of times, with different attribute values in each call.
The table below summarizes the various attribute settings, and the corresponding return values.
attribute Setting | ID | Return Value |
---|---|---|
OBJ_INFO_TYPE | 1 | SmallInt, representing the object type; the return value is one of the values listed in the table below (for example, OBJ_TYPE_LINE). This attribute from the DEF file is 1 (ObjectInfo( Object, 1 ) ). |
OBJ_INFO_PEN | 2 | Pen style is returned; this query is only valid for the following object types: Arc, Ellipse, Line, Polyline, Frame, Regions, Rectangle, and Rounded Rectangle. |
OBJ_INFO_BRUSH | 3 | Brush style is returned; this query is only valid for the following object types: Ellipse, Frame, Region, Rectangle, and Rounded Rectangle. |
OBJ_INFO_TEXTFONT | 2 | Font style is returned; this query is only valid for Text objects.
Note: If the Text object is contained in a mappable table (as opposed to a Layout window), the Font specifies a point size of zero, and the text height is controlled by the Map window's zoom distance.
|
OBJ_INFO_SYMBOL | 2 | Symbol style; this query is only valid for Point objects. |
OBJ_INFO_NPNTS | 20 | Integer, indicating the total number of nodes in a polyline or region object. |
OBJ_INFO_SMOOTH | 4 | Logical, indicating whether the specified Polyline object is smoothed. |
OBJ_INFO_FRAMEWIN | 4 | Integer, indicating the window ID of the window attached to a Frame object. |
OBJ_INFO_FRAMETITLE | 6 | String, indicating a Frame object's title. |
OBJ_INFO_NPOLYGONS | 21 | SmallInt, indicating the number of polygons (in the case of a region) or sections (in the case of a polyline) which make up an object. |
OBJ_INFO_NPOLYGONS+N | 21 | Integer, indicating the number of nodes in the Nth polygon of a region or the Nth section of a polyline.
Note: With region objects, MapInfo Pro counts the starting node twice (once as the start node and once as the end node). For example, ObjectInfo() returns a value of 4 for a triangle-shaped region.
|
OBJ_INFO_TEXTSTRING | 3 | String, representing the body of a Text object; if the object has multiple lines of text, the string includes embedded line-feeds (Chr$( 10 ) values). |
OBJ_INFO_TEXTSPACING | 4 | Float value of 1, 1.5, or 2, representing a Text object's line spacing. |
OBJ_INFO_TEXTJUSTIFY | 5 | SmallInt, representing justification of a Text object: 0 = left, 1 = center, 2 = right. |
OBJ_INFO_TEXTARROW | 6 | SmallInt, representing the line style associated with a Text object: 0 = no line, 1 = simple line, 2 = arrow line. |
OBJ_INFO_FILLFRAME | 7 | Logical: TRUE if the object is a frame that contains a Map window, and the frame's "Fill Frame With Map" setting is checked. |
OBJ_INFO_NONEMPTY | 11 | Logical, returns TRUE if a Multipoint object has nodes, or FALSE if the object is empty. |
OBJ_INFO_REGION | 8 | Object value representing the region part of a collection object. If the collection object does not have a region, it returns an empty region. This query is valid only for collection objects. |
OBJ_INFO_PLINE | 9 | Object value representing polyline part of a collection object. If the collection object does not have a polyline, it returns an empty polyline object. This query is valid only for collection objects. |
OBJ_INFO_MPOINT | 10 | Object value representing the Multipoint part of a collection object. If the collection object does not have a Multipoint, it returns an empty Multipoint object. This query is valid only for collection objects. |
OBJ_INFO_Z_UNIT_SET | 12 | Logical, indicating whether z units are defined. |
OBJ_INFO_Z_UNIT | 13 | String result: indicates distance units used for z-values. Returns an empty string if units are not specified. |
OBJ_INFO_HAS_Z | 14 | Logical, indicating whether the object has z-values. |
OBJ_INFO_HAS_M | 15 | Logical, indicating whether the object has m-values. |
The codes in the left column (for example, OBJ_INFO_TYPE) are defined through the MapBasic definitions file, MAPBASIC.DEF. Your program should Include "MAPBASIC.DEF" if you intend to call the ObjectInfo() function.
Each graphic attribute only applies to some types of graphic objects. For example, point objects are the only objects with Symbol attributes, and text objects are the only objects with Font attributes. Therefore, the ObjectInfo() function cannot return every type of attribute setting for every type of object.
If you specify OBJ_INFO_TYPE as the attribute setting, the ObjectInfo() function returns one of the object types listed in the table below.
OBJ_INFO_TYPE values | ID | Corresponding object type |
---|---|---|
OBJ_TYPE_ARC | 1 | Arc object |
OBJ_TYPE_ELLIPSE | 2 | Ellipse / circle objects |
OBJ_TYPE_LINE | 3 | Line object |
OBJ_TYPE_PLINE | 4 | Polyline object |
OBJ_TYPE_POINT | 5 | Point object |
OBJ_TYPE_FRAME | 6 | Layout window Frame object |
OBJ_TYPE_REGION | 7 | Region object |
OBJ_TYPE_RECT | 8 | Rectangle object |
OBJ_TYPE_ROUNDRECT | 9 | Rounded rectangle object |
OBJ_TYPE_TEXT | 10 | Text object |
OBJ_TYPE_MPOINT | 11 | Multipoint object |
OBJ_TYPE_COLLECTION | 12 | Collection of objects, such as points, polylines, and regions |
Error Conditions
The message, "Could Not Fetch Object error (650)" occurs when the object expression has no object. To handle this error, use an OnError GoTo
statement, or prevent the error by checking for a valid object expression using a test such as the following:
If Str$(myObject) <> "" Then
' the object expression does contain an object
' so it is safe to call ObjectInfo
End If
Example
Include "MAPBASIC.DEF"
Dim counter, obj_type As Integer
Open Table "city"
Fetch First From city
' at this point, the expression: city.obj
' represents the graphical object that's attached
' to the first record of the CITY table.
obj_type = ObjectInfo(city.obj, OBJ_INFO_TYPE)
Do Case obj_type
Case OBJ_TYPE_LINE
Note "First object is a line."
Case OBJ_TYPE_PLINE
Note "First object is a polyline..."
counter = ObjectInfo(city.obj, OBJ_INFO_NPNTS)
Note " ... with " + Str$(counter) + " nodes."
Case OBJ_TYPE_REGION
Note "First object is a region..."
counter = ObjectInfo(city.obj, OBJ_INFO_NPOLYGONS)
Note ", made up of " + Str$(counter) + " polygons..."
counter = ObjectInfo(city.obj, OBJ_INFO_NPOLYGONS+1)
Note "The 1st polygon has" + Str$(counter) + " nodes"
End Case
See Also:
Alter Object statement, Brush clause, Font clause, ObjectGeography() function, Pen clause, Symbol clause