Hi @hadhafang Use a ListIndexer and set "List Index To Copy" to "@Value(_element_count) - 1" because lists are numbered from 0. But if you just want the last coordinate, instead set the Mode in the CoordinateExtractor to "Specify Coordinate" with a "Coordinate Index" of -1.
Hi @hadhafang Use a ListIndexer and set "List Index To Copy" to "@Value(_element_count) - 1" because lists are numbered from 0. But if you just want the last coordinate, instead set the Mode in the CoordinateExtractor to "Specify Coordinate" with a "Coordinate Index" of -1.
Thank you for a quick answer @DanAtSafe. I had an old coordinate extractor i think. However it doesn't seem to work on my data set but i wrote a pythonCaller that does the same thing.
class FeatureProcessor(object):
def __init__(self):
self.featureList = r]
def input(self,feature):
self.featureList.append(feature)
xList=feature.getAttribute('_indices_normal{}.x')
feature.setAttribute('_x2', xListf-1])
self.pyoutput(feature)
def close(self):
pass
This question seems to be a continuation from the previous one:
"Error: @Coordinate is out of range -- it must be an integer i such that -n = i n, where n is the number of vertices in the feature".
If the input geometry was a vector such as Line or Polygon, @DanAtSafe's solution would be simplest. That is, you can extract desired coordinates directly by setting "Specify Coordinate" to the Mode parameter and "-1" to the Coordinate Index parameter in the CoordinateExtractor.
However, if the input geometry was a BRepSolid, the setting above could cause the same error reported in the previous question.
As you tried, it would be a workaround to extract all coordinates as a list attribute and then select one, but you need to be aware these points.
- Since the @sub function returns a floating point number even if the arguments were integers, the resulting value could not be used as a list index directly. You will have to convert the return value to an integer using the @int function, or use the - operator instead of the @sub function.
- A math operation embedded within a string expression has to be evaluated by the @Evaluate function.
For example, these expressions would return x-coordinate of the last vertex.
@Value(_indices_normal{@Evaluate(@int(@sub(@Value(_nbr_indices),1)))}.x)
@Value(_indices_normal{@Evaluate(@Value(_nbr_indices)-1)}.x)
Alternatively, you can calculate the target index at the first row in the AttriuteCreator, and use it in the following rows, as in:
The ListIndexer could also be used effectively.