Sketchup::InstancePath#leaf does not mention when it returns nil
Sketchup::InstancePath#leaf does not mention when it returns nil.
#leaf is the compliment to #root which does mention the case when nil is returned.
Basically these are meant as double-duty test methods so that a compound typing test is not needed:
unless ipath.to_a.first.is_a?(Sketchup::Group) ||
ipath.to_a.first.is_a?(Sketchup::ComponentInstance)
# root is not a complex object
else
# all is fine
end
... and of course the opposite for #leaf.
Note: It seems some new coders are expecting #leaf to act like Array#last,
and #root to act like Array#first.
(Perhaps add #first and #last methods to the Sketchup::InstancePath class ?)
When should #leaf return nil? Should a path ending at an instance (Group/Component) regard that to be the leaf? Is leaf only nil for empty paths?
Internally a leaf is a non-group/component. I think leaf will be nil when the path refer to a group/component only.
Agree.
Exactly thomthom Sorry i report a similar subject here : https://github.com/SketchUp/api-issue-tracker/issues/995
I did some tests, and actually leaf always returns nil when the last item of a instancePath is a group or a component
and this would also explain why we have always the error with drawing_element_visible?(instancePath)
Leaf must be a type of Sketchup::Drawingelement