Find the size and coordinates of the group

Untitled

post using google translate

I have group B (layer 1) and group C (layer 2) inside group A (layer 0).
Help me with the command to find
L1, L2, L3, X1, Y1, Z1 (the length of the side and the origin of A)
X2, Y2, Z2 (center coordinate B)
X3, Y3, Z3 (square origin C).

Thank you for your interest

You will need to get the transformations of the groups.
And if the objects are aligned to the model axis, then you can also get information from the groups’ bounding boxes.

You are going to need to do some work to learn Ruby, and the SketchUp API. Start by searching this category for old posts and examples.

ents = Sketchup.active_model.active_entities
group_a = ents.grep(Sketchup::Group).find { |grp| grp.name == "Group A" }
if group_a
  origin_a = group_a.transformation.origin
  x1, y1, z1 = origin_a.to_a
end
2 Likes

Thank you very much. I am also new to ruby, but right now I need to do some important work so I need to answer. can you help me with the command to get those values?

Bookmark these lists:

It is not my responsibility to do your work for you. We encourage new coders to at least make an attempt to solve their own coding challenges, and ask specific coding questions here in the forum, so that they can succeed themselves. It is the best way to learn.

I gave you a partial answer above for the coordinates of the “Group A” origin.

Group B’s bounds center will be within the entities of Group A and the coordinates will be relative to Group A’s transformation. If the center of the circle is also the origin of Group B, then this will be simpler as it will also be the origin of B’s transformation.


I showed above how to find a group by instance name. If you wish to find a group by layer name, then …

group_b = group_a.entities.grep(Sketchup::Group).find { |grp|
  grp.layer.name == "Layer 1"
}
2 Likes

As Dan tried to explain, there is no such thing as a “simple command” to get the values. You need to write a complex (but not necessarily complicated) methods, at least a snippet of code or your own plugin (extension).

Even experienced programmers take the time to figure out:

  • what is the specific task
  • what options need to be considered
  • what prerequisites must be met for the existing geometry
  • whether it is possible to meet these conditions
  • it is possible to consider these conditions at all in the Ruby API
  • and so on…

Dan gave a general guide and some examples on how to get started with the task, but is not expected to be “hippie-ready.”

Unfortunately, you need to delve a little deeper into the “mysteries” of Ruby, or ask a programmer to do it for you (most probably for money).

Of course, if you ask specific coding questions here in the forum, we are here to share our ideas and advise. :slight_smile:

3 Likes

Sincere thanks for your advice. I am Vietnamese, I am not good at English, so those documents are quite difficult for me. But okay, in my free time I will try to learn by myself to do it. thank!