How can I tell to which instance a dimension is attached?

If I create a component and place two instances and attach a dimension to each, then when moving an instance, the dimension moves with it. So Sketchup knows to which specific instance a dimension is attached. But, it seems to me that the API doesn’t reveal that information. The entity the dimension is attached to is part of ComponentDefinition and the position can be shared if the components tough/overlap.

Is there a way to find which specific instance a dimension is attached to?


I got the same problem and, thanks to the fact that SU return a couple of entity and point ([#
Sketchup::Vertex:0x000000113921f8, Point3d(0, 38.8976, 35.9055)]), the only solution I found is :

  1. Quering the viewport at the specified position to get entities at this point.
  2. Check which grabbed entity is an instance of the component definition of the entity returned by the start or end method from the dimension.

It works pretty well but it not an elegant or efficient way to do it…

1 Like

Have you looked in the API documentation and tried

Sketchup::DimensionLinear#start ⇒ [Sketchup::DrawingElement or nil, Sketchup::Point3d]
Sketchup::DimensionLinear#end  ⇒ [Sketchup::DrawingElement or nil, Sketchup::Point3d]

If I create a component and place two instances and attach a dimension to each

As Ittayd explained if the dimension is attached to different instances of the same définition the start and end methods only returns entity from the component definition and doesn’t tells you which istance is concerned.

@milmandre, this is what I’m currently doing. But like I mentioned, if the instances overlap, then I may get wrong of multiple results (depending on how I implement the method that discovers the instances). This isn’t very satisfactory.

To visualize the problem:

The method indeed returns the vertex (not the instance). However, the vertex is contained in a parent definition of whose instances only one has the dimension attached.

milmandre’s workaround is best. I think this has not been considered in the design of the dimension API (although internally SketchUp does it correctly). It should probably return the relative instance path ([ [instance, …, vertex], position]). Imagine constructing this situation by code with start=[vertex, position]: SketchUp does not know to which occurence of the vertex (in two instances of the same definition) it should attach the dimension and the dimension will disappear.

1 Like

Yes I got it but I don’t know how much your instances are overlapped. If they are exactly at the same position without any transform (rotate/scale) I haven’t found any solution yet but if they aren’t you can :

  1. Either zoom on a area closely framing your point in the viewport to have more accurate result when grabbing entities at point.
  2. Or check for each Instance grabbed which one match exactly with the combination entity and point returned.

Logged this flaw as SU-37001.

1 Like

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