You are here: Surpac Concepts > Macros > SCL > Object Manipulation > SclGetValueByIndex
GEOVIA Surpac

SclGetValueByIndex

Overview

This command is very closely related to the SclGetValueByName command.

Some Scl objects have one or more parameters whose values can be obtained, and in some cases set to satisfy the needs of the Scl programmer. A list of the Scl objects that this command can be applied to obtain values for attributes of interest can be found here

Only those attributes that have a physical storage equivalent (e.g. the X field for a point in a string file) may have their value set while other attributes whose values are dependent on a number of constituent objects may only be queried. A good example of this type of value is the 2D length of a segment since this is dependant on the points in the segment.

SclGetValueByIndex uses an integer index to determine the attribute whose value is to be returned. A value for this index must first be obtained using SclGetAttributeIndex. The reason for providing SclGetValueByIndex as an alternate method to SclGetValueByName is because it is slightly more efficient. This is particularly useful if the attribute values being obtained are being processed inside a for or while loop, and if there are likely to be many iterations of the loop.

Synopsis

$ObjectHandle SclGetValueByIndex $AttributeIndex
$ObjectHandle SclGetValueByIndex $AttributeIndex NewObjectHandle

Description

Returns the value of the requested attribute from the specified Scl object. Depending on the type of attribute for which the value is being obtained the value will either be returned as the result of the function or it will be assigned to the NewObjectHandle argument.

The second form of SclGetValueByIndex shown above is only used if the attribute being queried is a triangle vertex or neighbour triangle. That is, the attribute name is either v0, v1, v2, n0, n1 or n2.

Arguments

  • ObjectHandle
  • The ObjectHandle variable must contain a handle to an Scl object to which the SclGetValueByIndex command can be applied. Permitted Scl object types for the SclGetValueByIndex command are:

    • Swa objects
      • Point
      • Segment
      • String
      • Triangle
      • Trisolation
      • Triobject
      • Swa
    • Database objects
      • Row handle

  • AttributeIndex
  • Passed by Value. The index of the attribute for which the value is required is defined in the AttributeIndex variable. The value for AttributeIndex must first be obtained using the SclGetAttributeIndex command. Each Scl object type has a specific set of attributes that can be queried. The attribute names that can be queried for each Scl object type can be found here.

  • NewObjectHandle
  • If obtaining triangle vertices or neighbouring triangles using the attributes v0, v1, v2, n0, n1 or n2 then the handle of the object requested is assigned to the variable named here.

Returns

$ObjectHandle SclGetValueByIndex $AttributeIndex
This form of the SclGetValueByIndex command returns the value of interest as result of the command.

$ObjectHandle SclGetValueByIndex $AttributeIndex NewObjectHandle
This form of the SclGetValueByIndex command returns the results of the command into the NewObjectHandle variable. This form is only used if the AttributeIndex argument is for a triangle vertex or neighbour triangle.

If a triangle has one or more edges located on the trisolation boundary then no neighbour triangle exists for these particular edges. When querying a triangle object for neighbouring triangles (by using the attributes n0, n1, n2) a value of $SCL_TRUE is returned if a valid triangle object was assigned to the NewObjectHandle variable. If no neighbour triangle exists then a value of $SCL_FALSE is returned and NewObjectHandle should not be used.

Examples

#
# This example selects a point and then displays all X,Y and Z values for
# the segment containing the point using SclGetValueByIndex after obtaining
# the index values using SclGetAttributeIndex prior to executing the for loop
#
set status [ SclSelectPoint PointHandle "Select a point" \layer string_id segment_no point_no digx digy \
digz description ]
set xindex [$PointHandle SclGetAttributeIndex x]
set yindex [$PointHandle SclGetAttributeIndex y]
set zindex [$PointHandle SclGetAttributeIndex z]
while {$status == $SCL_OK} {
  $PointHandle SclGetParent SegmentHandle 
  $SegmentHandle SclGetParent StringHandle
  set count [$SegmentHandle SclCountItems]
  puts "String = [$StringHandle SclGetId], Segment = [$SegmentHandle SclGetId]"
  puts "X      , Y      , Z"
  for {set i 0} {$i < $count} {incr i} {
    $SegmentHandle SclGetItem PointHandle $i
    puts "[$PointHandle SclGetValueByIndex $xindex], [$PointHandle \
SclGetValueByIndex $yindex], [$PointHandle SclGetValueByIndex $zindex]"
  }
  set status [ SclSelectPoint PointHandle "Select a point" \
layer string_id segment_no point_no digx digy digz description ]
}