# Extrude face without deforming the initial face

**URL:** <https://forums.sketchup.com/t/extrude-face-without-deforming-the-initial-face/44338>\
**Category:** SketchUp\
**Tags:** sketchup, advice\
**Created:** [May 8, 2017, 1:19pm UTC](https://forums.sketchup.com/t/extrude-face-without-deforming-the-initial-face/44338 "2017-05-08T13:19:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bes](https://avatars.discourse-cdn.com/v4/letter/b/d26b3c/32.png) [@bes](https://forums.sketchup.com/u/bes)\
**Post date:** [May 8, 2017, 1:19pm UTC](https://forums.sketchup.com/t/extrude-face-without-deforming-the-initial-face/44338/1 "2017-05-08T13:19:46Z")

</div>

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:

```ruby
 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

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [May 8, 2017, 1:31pm UTC](https://forums.sketchup.com/t/extrude-face-without-deforming-the-initial-face/44338/2 "2017-05-08T13:31:41Z")

</div>

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

````auto
 ```ruby
 # your code here

````

```auto
That will make it much easier for all of us to read! Thanks.
```

---

<div class="post-metadata">

**Author:** ![bes](https://avatars.discourse-cdn.com/v4/letter/b/d26b3c/32.png) [@bes](https://forums.sketchup.com/u/bes)\
**Post date:** [May 8, 2017, 1:45pm UTC](https://forums.sketchup.com/t/extrude-face-without-deforming-the-initial-face/44338/3 "2017-05-08T13:45:15Z")

</div>

Thank you slbaumgartner

---

<div class="post-metadata">

**Author:** ![sdmitch](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/sdmitch/32/31265_2.png) [@sdmitch](https://forums.sketchup.com/u/sdmitch)\
**Post date:** [May 8, 2017, 3:18pm UTC](https://forums.sketchup.com/t/extrude-face-without-deforming-the-initial-face/44338/4 "2017-05-08T15:18:24Z")

</div>

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

 ![](https://global.discourse-cdn.com/sketchup/original/3X/a/4/a4593bf0214cb8fbbc445b8c563c5cbea2e6cf51.gif)

```ruby
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
}

```

---

<div class="post-metadata">

**Author:** ![bes](https://avatars.discourse-cdn.com/v4/letter/b/d26b3c/32.png) [@bes](https://forums.sketchup.com/u/bes)\
**Post date:** [May 8, 2017, 3:23pm UTC](https://forums.sketchup.com/t/extrude-face-without-deforming-the-initial-face/44338/5 "2017-05-08T15:23:57Z")

</div>

Perfect, Thank you so much sdmitch.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sketchup/original/3X/f/2/f2a121500b085ed60806607a82720b092d800bb3.png) [@system](https://forums.sketchup.com/u/system)\
**Post date:** [August 8, 2017, 5:20am UTC](https://forums.sketchup.com/t/extrude-face-without-deforming-the-initial-face/44338/6 "2017-08-08T05:20:22Z")

</div>

Closed on August 8, 2017, 5:20am UTC

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