Especially because the docs for
Sketchup::InstancePath# say …
The elements of an instance path can be accessed like an array.
In the tracker issue referenced below, I question that perhaps the phrase “can be accessed like an array.” might be removed, and readers directed to use
#to_a instead when needing to use negative indices or slices.
Except we are discussing the
Sketchup::InstancePath class here, not the entities collection.
But the idea of creating an array copy still holds true for any of the API collection classes that do not quite implement enumerable methods correctly.
# Where some_instance_path is a Sketchup::InstancePath object:
patharr = some_instance_path.to_a
# ... or ...
leaf = some_instance_path.to_a[-1]
leaf_parent = some_instance_path.to_a[-2]
first = some_instance_path.to_a.first
An example of walking the instance path in reverse order:
some_instance_path.to_a.reverse.each do |ent|
# do this ...
# do that ...
# a leaf, do other - it's a primitive, cpoint, cline,
# dimension, text callout, section plane, vertex, etc.
The above may also be a good candidate task for a
Issue logged (with this thread referenced) …