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