Search code examples
rubysketchup

How to make a hollow cylinder in SketchUp using the Ruby API


What I need to accomplish is basically a cylinder whose walls have zero thickness. Now if you need to understand better what I mean by this, imagine manually drawing a circle, then using the pushpull tool to make it a cylinder, after which you delete the top and bottom faces. At first, I used the method suggested in this post:

Punching a hole through a cylinder using Sketchup Ruby API

where the outer and inner radii had a difference of about 1e-02 meters, but now I realize it actually has to be an infinitesimal thickness, one where no matter how far you zoom-in, all you see is a line.

I went about trying to accomplish this with the following basic snippet of code:

entities = Sketchup.active_model.active_entities

circle = entities.add_circle(Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1), 20)
face = entities.add_face(circle)
face.pushpull(-10, true)

# now from here, it can be either pushpulled downwards by the same amount (10 in this case
# leaving only a bottom face)
# or the entity 'face' can be erased (leaving only a top face) as in the following

entities.erase_entities(face)

so my question is, how do I remove both faces so as to leave only the cylinder?

Thank you.


Solution

  • I found the answer, the solution is to do both. That is, pushpull inwards the same amount, then delete the face with: entities.erase_entities(face).

    entities = Sketchup.active_model.active_entities
    
    circle = entities.add_circle(Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1), 20)
    face = entities.add_face(circle)
    
    face.pushpull(-10, true)
    face.pushpull(10, true)
    
    entities.erase_entities(face)