Extrusion issue. Some faces don't extrude the correct way when using API

I’m having an issue where when I try to extrude the polygons extrude in different directions. I’m trying to go from 2D to 3D using a series of cross sections and this is happening to me for some reason.


for layer_name in layer do
    model.active_layer= layers_array[layer_prop[layer_name.to_sym]]
    ents = model.active_entities
    n = sorted_layers[layer_name].length-1 # get the number of faces in each layer
    for i in 0..n do # loop through the number of faces
      pts = [] # empty the pts array
      temp_len = sorted_layers[layer_name][i].x.length-1 # length of x array for each polygon (should be same length in y)
      for j in 0..temp_len do # loop through each point stored in each polygon
        x=sorted_layers[layer_name][i].x[j]# scaled up to mm
        z=sorted_layers[layer_name][i].z[j]  # scaled up to mm
        pts[j] = [x.mm,y.mm,z.mm]
      end
      face = ents.add_face pts # add the points to the face
      if face.normal.x == -1
        face.reverse!
      end
      face.pushpull 50.mm
    end
end

Could it be because some of the faces normal’s are kinda weird?

Your code snippet uses a bunch of variables that must be defined somewhere else: layer, layers_array, layer_prop, sorted_layers all are unknowns. Without knowing what they refer to it is not possible to diagnose your code.