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
        isOnY = true

    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
            if point.y > maxY
                maxY = point.y
            if point.z > maxZ
                maxZ = point.z
        puts "----"
    edges = []
    z = maxZ - opHeight
    if isOnX
        maxX = maxX - opOffset
        x = maxX - opWidth
        y = maxY
        p1 =,maxY,maxZ)
        p2 =,maxY,z)
        p3 =,maxY,maxZ)
        p4 =,maxY,z)
        newFace = entities.add_face p1,p2,p3,p4
        maxY = maxY - opOffset
        x = maxX
        y = maxY - opWidth
        p1 =,maxY,maxZ)
        p2 =,maxY,z)
        p3 =,y,maxZ)
        p4 =,y,z)

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


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 !

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…