Cutting solid using pushpull

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
1 Like

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…