Intersect Faces with Model via Ruby API

Hello all, I’ve written a script that puts a line grid on a given face. The issue I am having is that even though the lines/edges are on the face, not all of them are being combined with the face.

If I select everything(grid lines and face), right click>Intersect Faces>With Model, I get the desired result of all the lines that are on the face, becoming part of the face.

I haven’t however had any luck duplicating this result programmatically. I’ve tried grouping the lines and exploding them, which got me close but had some very strange effects, such as erasing sections of the existing face.

Please Help! Thanks in advance!


model = Sketchup.active_model


ents = model.active_entities


ss = model.selection


tr =

Use something like:

ents.intersect_with( false, tr, ents, tr, true, ents.to_a )

It is NOT a simple method !
There are many permutations of the arguments - entities, transformations and so on.
BUT what you want is probably the simplest…

1 Like

Thanks TIG, this seems like exactly what I was looking for, but when I run this code, this happens…

This is what was happening when I grouped and exploded the lines as well.
Any thoughts as to why this would happen?

have you tried edges.find_faces


John, I did try that, it had a similar effect, though not as severe. Also, after I solve this problem, I was intending to remove all the edges that are not part of a face. So that would be an issue.

Now you say the native tools do it as well !
How big is the grid you are intersecting ?
Very small dimensions can be flaky…

You could perhaps scale everything by x10, then intersect, then scale by x1/10 ?
Does this help with the native route ??

1 Like

what if you delete the off face ones first…
something like…

edges.each do |e|
next if e.faces.length == 2
e.erase! if e.faces.length == 0
next if e.deleted?

When I did this from the UI as originally described, the result was perfect. When I group and explode(programmatically or through the UI), the results are ‘flaky’.[quote=“TIG, post:6, topic:21799”]
You could perhaps scale everything by x10, then intersect, then scale by x1/10 ?
I just tried, the grid being 150 units, unfortunately this didn’t fix it.

This also gave me some wacky results

Victory! I was able to get this to work by implementing this…

but instead of selecting the entire grid, I added it to an iteration per edge.
Thanks for your help guys!

1 Like