Extrude face without deforming the initial face

Hi, I am new in Ruby. Can someone please explain me how can I extrude a face without any deformation of the initial face. I manage to do this for circle but not for rectangle. Please see:

 model = Sketchup.active_model # Open model
 ents = model.entities # All entities in model
 sel = model.selection # Current selection

@edges = []

       ents.each do |e|
         if e.is_a? Sketchup::Edge
            @edges << e
         end
      end

def gh # -------------------------------------------------------------------------------------------------------- this works
0.upto(@edges.count-1) {|x|
model = Sketchup.active_model # Open model
entities = model.entities # All entities in model
new_comp_def_xy = Sketchup.active_model.definitions.add("extrude") 
center = Geom::Point3d.new @edges[x].start.position
vector = Geom::Vector3d.new [@edges[x].end.position.x - @edges[x].start.position.x,@edges[x].end.position.y - @edges[x].start.position.y,@edges[x].end.position.z - @edges[x].start.position.z]            
tr = Geom::Transformation.new(center)
circle = new_comp_def_xy.entities.add_circle center, vector, 0.025.m
circle_face = new_comp_def_xy.entities.add_face(circle)
circle_face.followme @edges[x]
tr = Geom::Transformation.new
rest = Sketchup.active_model.active_entities.add_instance(new_comp_def_xy, tr )
}
end


def asd # ------------------------------------------------------------------------------------------------ not working properly
0.upto(@edges.count-1) {|x|
model = Sketchup.active_model # Open model
entities = model.entities # All entities in model
new_comp_def_xy = Sketchup.active_model.definitions.add("extrude") 
vector = Geom::Vector3d.new [@edges[x].end.position.x - @edges[x].start.position.x,@edges[x].end.position.y - @edges[x].start.position.y,@edges[x].end.position.z - @edges[x].start.position.z]
gp = entities.add_group()
                  points = Array.new
                  points[0] = [0.03.m, 0.03.m, 0.m]
                  points[1] = [0.03.m, -0.03.m, 0]
                  points[2] = [-0.03.m, -0.03.m, 0]
                  points[3] = [-0.03.m, 0.03.m, 0]
                  points[4] = [0.03.m, 0.03.m, 0.m]
                  newface1 = new_comp_def_xy.entities.add_face(points)
                newface1.reverse! 
                status = newface1.pushpull @edges[x].length
                point = Geom::Point3d.new
                as = Geom::Transformation.new(@edges[x].start.position)
Sketchup.active_model.active_entities.add_instance(new_comp_def_xy, as)
                        points.clear            
}
end

thank you in advance

Please edit your post and surround the code with lines like these (triple backtick at the left margin):

 ```ruby
 # your code here
That will make it much easier for all of us to read!  Thanks.

Thank you slbaumgartner

You need to treat the rectangle the same as the circle by defining the transformation as the center,vector

model = Sketchup.active_model # Open model
ents = model.entities # All entities in model
sel = model.selection # Current selection

@edges = sel.grep(Sketchup::Edge)

0.upto(@edges.count-1) {|x|
  new_comp_def_xy = Sketchup.active_model.definitions.add("extrude")
  center,vector = @edges[x].line
  gp = ents.add_group()
  points = Array.new
  points[0] = [0.03.m, 0.03.m, 0.m]
  points[1] = [0.03.m, -0.03.m, 0]
  points[2] = [-0.03.m, -0.03.m, 0]
  points[3] = [-0.03.m, 0.03.m, 0]
  points[4] = [0.03.m, 0.03.m, 0.m]
  newface1 = new_comp_def_xy.entities.add_face(points)
  newface1.reverse!
  status = newface1.pushpull @edges[x].length
  point = Geom::Point3d.new
  as = Geom::Transformation.new(center,vector)
  Sketchup.active_model.active_entities.add_instance(new_comp_def_xy, as)
  points.clear
}

Perfect, Thank you so much sdmitch.

This topic was automatically closed after 91 days. New replies are no longer allowed.