Points using get_attribute are different from set_attribute, is there a bug?(SKP 2017)

I construct a mesh using Geom::PolygonMesh which grouped, and save points using Entity#set_attribute of the group object. I retrieve the value of an attribute, which different when selected or not.

ruby code here:
#create
my_mesh = some_face.mesh
group = Sketchup.active_model.entities.add_group
group.entities.add_faces_from_mesh(my_mesh)
#Geom::Point3d Array
group.set_attribute(“my mesh”, “shape”, point3Ds)

#when my_mesh selected
arr_selected = group.set_attribute(“my mesh”, “shape”, point3Ds)
#when my_mesh no selected
arr_no_selected = group.set_attribute(“my mesh”, “shape”, point3Ds)

#return false
(0…arr_selected.count).each do |i|
#no equal
return false if arr_selected[i] .distance(arr_no_selected[i]) > 0.00001
end


There is a difference between selecting and opening for edit. When you open a group or instance for edit you enter that context. The coordinates will be different, yes. This is just how the SketchUp engine works.

When you are outside the group entities context, the mesh coordinates will be in the group’s local coordinates. When you are inside the group edit context, the core API functions return points in model coordinates.

1 Like

Points and probably also Vectors are transformed whenever the entity is transformed (including when the container opens and the axes changes). This can be extremely handy if you want to define locations in the parent drawing context, e.g. save the end points of a wall group in the coordinate system the wall group is placed in. If you don’t want to transform the coordinates, e.g. if you want them to be relative an internal coordinate system, you cna convert them to arrays before writing them as attributes.

1 Like

It’s the value of an attribute, not mesh coordinates.

Thank you for your replying which give me an idea!

Yes we know. The former is storing the latter, … as Julia explains above.