SclSetValueByIndex
Overview
This command is very closely related to the SclSetValueByName 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 set 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 dependant 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.
SclSetValueByIndex 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 SclSetValueByIndex as an alternate method to SclSetValueByName is because it is slightly more efficient. This is particularly useful if the attribute values being set are being processed inside a for or while loop, and if there are likely to be many iterations of the loop.
Synopsis
$ObjectHandle SclSetValueByIndex $AttributeIndex $Value
Description
Set the value for the attribute represented by AttributeIndex for the specified Scl object.
Arguments
- ObjectHandle
- AttributeIndex
- Value
This variable must contain the handle to an Scl object that permits attribute values to be set.
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.
Passed by value. The value that is to be assigned to the attribute of interest for the specified Scl object. Note that if coordinate values of points are changed, and the segments containing these points have been drawn in a viewport, the Scl programmer is responsible for redrawing the data in the viewport using the SclDraw command.
Examples
#
# This example selects a point and then adds 5 to the X value of each point
# in the segment and then redraws the segment in the viewport.
#
# The x values are queried and set using the Scl(Get/Set)ValueByIndex commands
#
set status [ SclSelectPoint PointHandle "Select a point" layer string_id \
segment_no point_no digx digy digz description ]
set xindex [$PointHandle SclGetAttributeIndex x]
while {$status == $SCL_OK} {
$PointHandle SclGetParent SegmentHandle
$SegmentHandle SclGetParent StringHandle
set count [$SegmentHandle SclCountItems]
for {set i 0} {$i < $count} {incr i} {
$SegmentHandle SclGetItem PointHandle $i
set x [$PointHandle SclGetValueByIndex $xindex]
set x [expr $x + 5]
$PointHandle SclSetValueByIndex $xindex $x
}
$SegmentHandle SclDraw
set status [ SclSelectPoint PointHandle "Select a point" layer string_id \
segment_no point_no digx digy digz description ]
}
|