# Cutting solid using pushpull

**URL:** <https://forums.sketchup.com/t/cutting-solid-using-pushpull/9012>\
**Category:** Ruby API\
**Created:** [March 24, 2015, 9:26am UTC](https://forums.sketchup.com/t/cutting-solid-using-pushpull/9012 "2015-03-24T09:26:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pawelelele](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@pawelelele](https://forums.sketchup.com/u/pawelelele)\
**Post date:** [March 24, 2015, 9:26am UTC](https://forums.sketchup.com/t/cutting-solid-using-pushpull/9012/1 "2015-03-24T09:26:35Z")

</div>

Hello !

I am trying to cut openings in solid using pushpull on a face. I recreate steps needed to achieve this via user interface in Ruby API, but opening is not cut - no matter how much I push or pull the face. Does anyone have a working solution for this kind of stuf??

My code:

```
    model = Sketchup.active_model
    entities = model.entities
    entity = entities[0]

    #define opening size
    opHeight = 100
    opWidth = 40

    opOffset = 60
    
    if entity.typename == 'ComponentInstance'
    
    isOnX = false
    isOnY = false
    bBox = entity.bounds
    
    if (bBox.max.x- bBox.min.x) > (bBox.max.y - bBox.min.y)
        isOnX = true
    else
        isOnY = true
    end

    array = entity.explode
    face = array[1]
    edges = face.edges
    maxX = -12345
    maxY = -12345
    maxZ = -12345
    
    
    for edge in edges
        line = edge.line
        puts "LINE"

        for point in line
            puts point
            if point.x > maxX
                maxX = point.x
            end
            if point.y > maxY
                maxY = point.y
            end
            if point.z > maxZ
                maxZ = point.z
            end
        end
        puts "----"
    end
    
    edges = []
    z = maxZ - opHeight
    if isOnX
        maxX = maxX - opOffset
        x = maxX - opWidth
        y = maxY
        p1 = Geom::Point3d.new(maxX,maxY,maxZ)
        p2 = Geom::Point3d.new(maxX,maxY,z)
        p3 = Geom::Point3d.new(x,maxY,maxZ)
        p4 = Geom::Point3d.new(x,maxY,z)
        
        newFace = entities.add_face p1,p2,p3,p4
    else
        maxY = maxY - opOffset
        x = maxX
        y = maxY - opWidth
        p1 = Geom::Point3d.new(maxX,maxY,maxZ)
        p2 = Geom::Point3d.new(maxX,maxY,z)
        p3 = Geom::Point3d.new(maxX,y,maxZ)
        p4 = Geom::Point3d.new(maxX,y,z)

        puts p1
        
        newFace = entities.add_face p4,p2,p1,p3
        newFace.pushpull(-30, true)
    end
    
end

```

---

<div class="post-metadata">

**Author:** ![TIG](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tig/32/198_2.png) [@TIG](https://forums.sketchup.com/u/TIG)\
**Post date:** [March 24, 2015, 1:46pm UTC](https://forums.sketchup.com/t/cutting-solid-using-pushpull/9012/2 "2015-03-24T13:46:29Z")

</div>

Your code is a muddle…

You assume there is only on entity in the model and it’s a component\_instance.  
Why not use say

```
 entity = model.selection[0]

```

Then there’s your ‘`array`’

```
array = entity.explode
face = array[1]
edges = face.edges

```

The ‘`array`’ is NOT guaranteed to always have a face as its second element !  
Whereas…

```
face = array.grep(Sketchup::Face)[0]

```

will work.

However, I suspect there are some far easier ways to do what it is you want [it’s not very clear from your post, or the code]  
Can you write down what you want to do “in words” - NOT in code - that way we might better understand your aims and suggest improved approaches to your coding…
