# How to use entity intersect function but do not trim/delete the original groupl

**URL:** <https://forums.sketchup.com/t/how-to-use-entity-intersect-function-but-do-not-trim-delete-the-original-groupl/52708>\
**Category:** Ruby API\
**Tags:** intersect\
**Created:** [October 4, 2017, 10:11pm UTC](https://forums.sketchup.com/t/how-to-use-entity-intersect-function-but-do-not-trim-delete-the-original-groupl/52708 "2017-10-04T22:11:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shang](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@Shang](https://forums.sketchup.com/u/Shang)\
**Post date:** [October 4, 2017, 10:11pm UTC](https://forums.sketchup.com/t/how-to-use-entity-intersect-function-but-do-not-trim-delete-the-original-groupl/52708/1 "2017-10-04T22:11:55Z")

</div>

Recently, I found the intersect function between two groups can detect if the two groups are intersected or not. But the function only returns to a residual group. I just want to detect the intersection instead of really modify the original entities/groups. Any ideas?

P.S.

For example, i just need a check like below:

if (A.intersect(B) == nil) and return a true of false without deleting/modifying either A or B.

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [October 4, 2017, 10:15pm UTC](https://forums.sketchup.com/t/how-to-use-entity-intersect-function-but-do-not-trim-delete-the-original-groupl/52708/2 "2017-10-04T22:15:33Z")

</div>

entities#intersect\_with returns an array of the new edges it created (contrary to what the docs say). The array is empty if there is no intersection. You could erase the edges to undo the intersection if you just wanted to know.

Edit: a further thought. Intersection is a pretty heavy operation. You could avoid some waste if you check whether the bounding boxes overlap first. If they don’t, intersection isn’t possible.

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [October 4, 2017, 10:21pm UTC](https://forums.sketchup.com/t/how-to-use-entity-intersect-function-but-do-not-trim-delete-the-original-groupl/52708/3 "2017-10-04T22:21:23Z")

</div>

or you may be able to use the `bounds`…

```ruby
group_a.bounds.intersect(group_b.bounds).valid?

```

which will return true or false

steve’s edit came as I posted…

john

---

<div class="post-metadata">

**Author:** ![Shang](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@Shang](https://forums.sketchup.com/u/Shang)\
**Post date:** [October 5, 2017, 3:02pm UTC](https://forums.sketchup.com/t/how-to-use-entity-intersect-function-but-do-not-trim-delete-the-original-groupl/52708/4 "2017-10-05T15:02:43Z")

</div>

Thanks for your reply. I just tried the intersect\_with function and test on my model of two intersected polygon A and B as:

res = entities.intersect\_with(true, IDENTITY, A, IDENTITY, false, B)

And the function works good.

But I have a follow up question: the result showed the intersected line is grouped with A, so how can I blindly delete it without exploding it?

---

<div class="post-metadata">

**Author:** ![Shang](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@Shang](https://forums.sketchup.com/u/Shang)\
**Post date:** [October 5, 2017, 3:04pm UTC](https://forums.sketchup.com/t/how-to-use-entity-intersect-function-but-do-not-trim-delete-the-original-groupl/52708/5 "2017-10-05T15:04:36Z")

</div>

Thanks for your reply. Yes. I have tried the bounds before, but I think it is not accurate for sphere or cone structure. ‘intersect’ function looks more accurate though.

---

<div class="post-metadata">

**Author:** ![Shang](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@Shang](https://forums.sketchup.com/u/Shang)\
**Post date:** [October 5, 2017, 3:27pm UTC](https://forums.sketchup.com/t/how-to-use-entity-intersect-function-but-do-not-trim-delete-the-original-groupl/52708/6 "2017-10-05T15:27:18Z")

</div>

Just get solved. The returned result is the intersected line. Thanks.

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [October 5, 2017, 4:46pm UTC](https://forums.sketchup.com/t/how-to-use-entity-intersect-function-but-do-not-trim-delete-the-original-groupl/52708/7 "2017-10-05T16:46:24Z")

</div>

A in your snippet is the entities collection where the edges from the intersection will be added. If you create a temporary group you can use its entities for A and that will isolate them from actually cutting any other edges or faces.

One thing to beware if you do this: SketchUp is very aggressive about deleting empty groups, and it could become invalid before the intersection! The usual workaround is to add a cpoint immediately after creating the group.

---

<div class="post-metadata">

**Author:** ![Shang](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@Shang](https://forums.sketchup.com/u/Shang)\
**Post date:** [October 6, 2017, 4:17am UTC](https://forums.sketchup.com/t/how-to-use-entity-intersect-function-but-do-not-trim-delete-the-original-groupl/52708/8 "2017-10-06T04:17:44Z")

</div>

Thanks for the remind. I have give a test on several simply polygon intersection cases, and it works fine. Just use entities\_erase to delete the returned value of intersect\_with can delete the line arrays without changing entities.length and existing group (index). I am not sure what exactly the cpoint works for, looks like can help locate a group by a point, will try if got some errors.

My basic plan is to manually do some animations (Like build a house) using the existing tools (SU animator, keyframe; I have tried the Transformation and sleep combination to do the animation but every time it freeze my computer). Then uses Api to automatically highlights the intersected objects (groups) during the animation. But then I find I am not able to do this during the animation, a workaround is to stop at each scene and trigger the intersect check. Would be appreciate if there is better idea. Thanks.

---

<div class="post-metadata">

**Author:** ![Neil\_Burkholder](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@Neil\_Burkholder](https://forums.sketchup.com/u/Neil_Burkholder)\
**Post date:** [October 9, 2017, 9:59pm UTC](https://forums.sketchup.com/t/how-to-use-entity-intersect-function-but-do-not-trim-delete-the-original-groupl/52708/9 "2017-10-09T21:59:55Z")

</div>

> [@Shang](#):
>
> I have tried the Transformation and sleep combination to do the animation but every time it freeze my computer).

Try using a timer rather than sleep.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sketchup/original/3X/f/2/f2a121500b085ed60806607a82720b092d800bb3.png) [@system](https://forums.sketchup.com/u/system)\
**Post date:** [January 9, 2018, 1:59pm UTC](https://forums.sketchup.com/t/how-to-use-entity-intersect-function-but-do-not-trim-delete-the-original-groupl/52708/10 "2018-01-09T13:59:57Z")

</div>

Closed on January 9, 2018, 1:59pm UTC

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