# How can I use the ruby API to programatically create a manifold from this group

**URL:** <https://forums.sketchup.com/t/how-can-i-use-the-ruby-api-to-programatically-create-a-manifold-from-this-group/134661>\
**Category:** Ruby API\
**Tags:** sketchup, advice, bug, modeling, components\
**Created:** [August 27, 2020, 8:41pm UTC](https://forums.sketchup.com/t/how-can-i-use-the-ruby-api-to-programatically-create-a-manifold-from-this-group/134661 "2020-08-27T20:41:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwatts](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@cwatts](https://forums.sketchup.com/u/cwatts)\
**Post date:** [August 27, 2020, 8:41pm UTC](https://forums.sketchup.com/t/how-can-i-use-the-ruby-api-to-programatically-create-a-manifold-from-this-group/134661/1 "2020-08-27T20:41:30Z")

</div>

The skp attached contains the desired goal and the problem. The problem is created programatically via a followme function and will be part of a program I am designing that will create 3D layouts of semiconductor devices. Therefore, I can’t just do an add\_line in there and delete the faces. The deleting of the faces I can do it’s adding the line at the intersect of the faces that I can’t figure out.  
[example.skp](https://forums.sketchup.com/uploads/short-url/2KIGRT1NsKLnz97dV2wTtIfBeTY.skp) (76.5 KB)

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [August 27, 2020, 9:13pm UTC](https://forums.sketchup.com/t/how-can-i-use-the-ruby-api-to-programatically-create-a-manifold-from-this-group/134661/2 "2020-08-27T21:13:23Z")

</div>

> [@cwatts](#):
>
> The skp attached contains the desired goal and the problem.

There is no annotation in the model to describe what is what and the problem.

I see 2 upside down pyramids.

> [@cwatts](#):
>
> The problem is created programatically via a followme function …

We ask that you provide a snippet of what you have tried at least … (and of course that you at least try.) 😉

How are you determining the vertices of this pyramid ? It might **not** be a solution for `followme`.

Perhaps draw a flat view (as if looking down from above, or looking up from below) with the x edges meeting the short edge. Then transform the vertices of that short edge upwards (or downwards) parallel to the `Z_AXIS` to create the top surfaces of the pyramid.  
Lastly do a `find_faces` call on one of the base edges to close the pyramid making it manifold.

---

<div class="post-metadata">

**Author:** ![cwatts](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@cwatts](https://forums.sketchup.com/u/cwatts)\
**Post date:** [August 27, 2020, 9:24pm UTC](https://forums.sketchup.com/t/how-can-i-use-the-ruby-api-to-programatically-create-a-manifold-from-this-group/134661/3 "2020-08-27T21:24:04Z")

</div>

Sorry, the skp is labeled in the outliner. I was just working on the script to get it started, I have been using the console+ to try things out so far.

The followme function creates the pyramid seen and I can’t really change that part. What I can do is manipulate the pyramid after it has been created.

I tried to use find faces, it didn’t work because where the faces intersect there is no line.

This is the issue here.

 ![image](https://global.discourse-cdn.com/sketchup/original/3X/c/6/c6562b60d0deffc7239d0201a2d9e900ee04f02c.png)  
This is what I am going for.  
 ![image](https://global.discourse-cdn.com/sketchup/original/3X/2/5/2514a7581f1d4284fc97d4945fecb0a70481ed2d.png)

---

<div class="post-metadata">

**Author:** ![cwatts](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@cwatts](https://forums.sketchup.com/u/cwatts)\
**Post date:** [August 27, 2020, 10:06pm UTC](https://forums.sketchup.com/t/how-can-i-use-the-ruby-api-to-programatically-create-a-manifold-from-this-group/134661/4 "2020-08-27T22:06:29Z")

</div>

Solved it. For some reason this didn’t work before but it does now.

```ruby
# standard inclusions
model = Sketchup.active_model
ents = model.entities

# get the groups
groups = ents.grep(Sketchup::Group)

# get group of interest (for this skp it is the first one)
goi = group.first

# intersect faces within the group with each other.
def intersect_faces_within_group(group)
  # get the group entities
  g_ents = group.entities
  
  # new empty transformation
  tr = Geom::Transformation.new()
  
  # create our intersection
  g_ents.intersect_with( false, tr, g_ents, tr, true, g_ents.to_a)
  
  # group edges
  g_edges = g_ents.grep(Sketchup::Edge)
  
  # delete any edges that don't touch more than 1 face.
  g_edges.each{ |e| e.erase! if e.faces.length < 2}
end

intersect_faces_within_group(goi)

```

[example.skp](https://forums.sketchup.com/uploads/short-url/uLE7izeW6eIfPwapPbf4DlnWSEr.skp) (76.5 KB)

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [August 27, 2020, 11:07pm UTC](https://forums.sketchup.com/t/how-can-i-use-the-ruby-api-to-programatically-create-a-manifold-from-this-group/134661/5 "2020-08-27T23:07:47Z")

</div>

> [@cwatts](#):
>
> ```ruby
> # create our intersection
> g_ents.intersect_with( false, tr, g_ents, tr, true, g_ents.to_a)
> 
> ```

That is weird. Intersecting a group’s entities with itself and putting the result inside the group.

I would have thought the both transformation arguments should be `tr = group.transformation`.

* * *

Another possibility might be to identify the overlapping faces and intersect the planes.

```ruby
iline = Geom::intersect_plane_plane( face1.plane, face2.plane )

```

And then get the points where the edges (of one of the faces) cross the line …

```ruby
pts = face1.edges.map {|edge| Geom::intersect_line_line(edge.line, iline) }
pts.compact! # remove the 1 nil for the bottom edge.
group.entities.add_edge(*pts)

```

However it might be necessary to transform the points depending upon what editing context the `model.active_entities` is at the time (before adding the new edge.)

---

<div class="post-metadata">

**Author:** ![cwatts](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@cwatts](https://forums.sketchup.com/u/cwatts)\
**Post date:** [August 27, 2020, 11:28pm UTC](https://forums.sketchup.com/t/how-can-i-use-the-ruby-api-to-programatically-create-a-manifold-from-this-group/134661/6 "2020-08-27T23:28:14Z")

</div>

I think the method I outlined works a little better for my situation because the object may not always be a square pyramid. But, in a situation as you describe your method does seem like a good option. I would say, however, my method may be more effective for someone doing a roof using the followme tool in ruby API to remove overlapping parts you don’t want.
