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

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?


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.

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.

or you may be able to use the bounds


which will return true or false

steve’s edit came as I posted…


1 Like

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?

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.

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

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.

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.

Try using a timer rather than sleep.

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