Finding and grouping resulting separate objects within group after using .subtract(group)?

Hi, SketchUp community!

This is my first time posting here, so I apologise for any beginner mistakes!

I am currently working on my first plugin - a timber framing tool that generates a frame based on a predefined/ pre-modelled wall face.

I’ve seen and tried Meedek’s plugin, which is simply amazing but does not quite work for my very specific workflow.

At the moment I am in the process of frame generation and stumbled across the .subtract(group) method which would be ideal to split frames at locations of window/doors etc.
When subtracting one group from another, it will leave two parts of the frame, which I would need to group into two separate groups. The screenshots below show the process using .subtract(group) as explained on the API Documentation. The last screenshot would be the desired end result - both objects grouped together individually.

entities = Sketchup.active_model.entities
group1 = entities[0]
group2 = entities[1]
result = group1.subtract(group2)

I can’t seem to find an easy method/solution to select and group each individual object to be put into an array which I could then use in another method to modify these groups. (Or I have not found the right one yet!)

Any advice would be much appreciated!

For example you can find an edge in a resulted entities.

edge = result.entities.grep(Sketchup::Edge).first

Then you can use the Edge#all_connected instance_method to get one part (the array of the edge and entities connected to that edge)

sub_ents1 = edge.all_connected

the other part could be for example:

sub_ents2 = result.entities.to_a - sub_ents1

Your profile say you are using SketchUp Make (desktop). SketchUp Version: 2018

  • The ‘subtract method’ is a Pro only feature.

  • There is no 2018 version of SketchUp Make, the last one is 2017.


Thanks a lot for that Dezmo!

Great idea using the edge.all_connected. This will give me a great start to figure out all other parts within the group. As there will possibly be more than just two parts I might use this logic to loop through the group by grouping one part, taking the next, grouping that one, etc…

I will keep browsing the API learn about some more methods to use in the future. Using the Sketchup API, it’s quite an interesting change from just modelling in the program and really forces you to think outside the box!

Thanks again.