I meant in relation to what collection. Your answer is the Entities
collection.
I think that the index returned is an index in relation to your SUGeometryInputRef
object’s temporary collection, not the model’s entities collection object. However if you add the geometry to a new empty group’s entities then I’d think perhaps that the indices may be retained.
You should be aware that none of the APIs give a contract that the indices within the entities collection is maintained in any particular order. The entities may be in added (creation) order initially, but later after housekeeping or after geometry is removed and edited, etc., the members of the collection may be reordered. You may find that the order might change after a save and reopening the model.
Now if you are getting indices just after having added the geometry and have not made any other changes then you could likely use indices temporarily. But the APIs were recently given persistent IDs that are meant for coders to use to “tag” entities.
Anyway, in Ruby the array (and enumerable mixin library) gives core language methods to get an index for a object in a collection. I would imagine C language also have this core language function that is not per se an API function.
At the worst, if you cannot find a core C array function, you’d just write up your own function to iterate the entities collection to find a match to the objects you pass in as a parameter, and break out returning the index when the match is true.
The simplified heart of the C code for Ruby’s Array#index()
method is the following.
It is as I said a simple matching iterator wrapped up in a function …
static VALUE
get_index(int argc, VALUE *argv, VALUE ary)
{
VALUE val;
long i;
if (argc == 0) {
return Qnil;
}
rb_check_arity(argc, 0, 1);
val = argv[0];
for (i=0; i<RARRAY_LEN(ary); i++) {
VALUE e = RARRAY_AREF(ary, i);
if (rb_equal(e, val)) {
return LONG2NUM(i);
}
}
return Qnil;
}
This should give you an idea.
There are also these C API helpers …