Several bugs using add_dimension_linear in the Ruby API

Hi,

First, I think there’s a bug in Sketchup itself:

  1. start a new model
  2. draw a vertical (blue) line, top to bottom
  3. make a group of the line (create another line, make group, open the group, delete the second line, close the group)
  4. create a linear dimension of the line (outside of the group), top to bottom

result: the dimension is not associated with the bottom point. That is, if you open the group and move the bottom point of the line, the dimension is not updated (if you move the top point, it does)

now , to the API part, if I do
entities.add_dimension_linear(dim.start, dim.end, dim.offset_vector)

where ‘dim’ is the dimension above (e.g. select it, then model.selection[0]), then: you get an ArgumentError, since dim.end is invalid. But I think it should be valid.

now, do entities.add_dimension_linear(dim.start, dim.end[1], dim_offset_vector). the result is that the new dimension has a weird start position. E.g. dim.start is [#<Sketchup::Vertex:0x0000000d38a128>, Point3d(33.9892, 101.274, 0)], but dim2.start (dim2 is the new dimension) is [#<Sketchup::Vertex:0x0000000d38a128>, Point3d(0, 0, 58.8976)]

Trying to create the dimension by specifying the start as [dim.start[0], dim.start[1]] doesn’t help, nor explicitly specifying the point in the second element of the array

This all seems to be since the end point is the origin of the group. This seems like a pretty common scenario to me

Also, create two edges, each within its own group. create a dimension outside of the groups. Create a new one using add_dimension_linear. The new dimension is not associated with one of the points. It seems to be, but when moving the lines, it doesn’t change with one of them

Seems like also creating a group (from two lines) and rotating it create a similar bug where a dimension that is created from the start/end/offset of another comes out skewed and returning different start/end/offset (creating it in parent.entities of the original dimension). looking at the value of start and end, they seem to be transformed to those of the original dimension. So I tried creating the dimension by applying transformations to the start and end, this doesn’t work

UPDATE: another example. I create a dimension with point [0,0,0] on the original’s start and end but when it is created its start has a different point:

dim5 = dim.parent.entities.add_dimension_linear([dim.start[0], [0,0,0]], [dim.end[0], [0,0,0]], [20,0,0])
#<Sketchup::DimensionLinear:0x000000109aa5a0>
dim5.start
[#<Sketchup::Vertex:0x00000011ac4a20>, Point3d(68.4499, 0, 42.0472)]

UPDATE2: though i don’t know exactly how to recreate this (happened in a complex model), I have a dimension that shows as ‘3.0’. but when I use dim.text it returns ‘1.0’. setting dim.text to ‘’ or ‘1.0’ and then ‘’ doesn’t help. It seems to be related to setting dim.text to ‘’ when the dim is inside a group that is closed. if I open the group and get dim.text, it returns 3.0. when i close the group it again shows 1.0

UPDATE3: so it seems the text issue is because the group is scaled. looks like a bug. also dim.end[1].distance_to_line([dim.start[1], dim.offset_vector]).to_l returns 1.0

UPDATE4: from the console:

dim.parent.instances[0].bounds.diagonal
~ 686.7
dim.parent.instances[0].bounds.diagonal
~ 228.9

The difference is because between executing the first expression and the second, i closed the active group. how can the bounds change? the local_bounds.diagonal is 228.9 regardless.

This topic was automatically closed after 91 days. New replies are no longer allowed.