SketchUp / ruby-api-docs

SketchUp Ruby API Documentation
18 stars 9 forks source link

InstancePath#persistent_id_path returning wrong path when leaf is an instance #41

Closed Eneroth3 closed 6 years ago

Eneroth3 commented 6 years ago

InstancePath#persistent_id_path drops the leaf if it is a ComponentInstance or a Group. The returned PID path simply points to the parent container, not the child container the instance path points at.

model = Sketchup.active_model
group1 = model.entities.add_group
group2 = group1.entities.add_group
cpoint = group2.entities.add_cpoint(ORIGIN)

# Groups and component instances as leafs are ignored by #persistent_id_path,
# resulting in a PID path that can't be used to restore the original instance
# path at a later point.
puts
path = Sketchup::InstancePath.new([group1, group2])
puts path.to_a
pid_path = path.persistent_id_path
# Expects a path with 2 PIDs here.
puts pid_path
path1 = model.instance_path_from_pid_path(pid_path)
# This is not the same path as path.
puts path1.to_a

# When the leaf is some other entity, e.g. a ConstructionPoint, the
# #persistent_id_path includes it, resulting in a PID path that can be used to
# restore the original instance path at a later point, as expected.
puts
path = Sketchup::InstancePath.new([group1, group2, cpoint])
puts path.to_a
pid_path = path.persistent_id_path
# Path contains 3 PIDs as expected.
puts pid_path
path1 = model.instance_path_from_pid_path(pid_path)
# This path is the same as the original one, pointing at the cpoint.
puts path1.to_a
Eneroth3 commented 6 years ago

Sorry, posted in wrong repo.

DanRathbun commented 6 years ago

Moved to: https://github.com/SketchUp/api-issue-tracker/issues/21