Chapter 7 – Creating Geometry Using Ruby Scripting

In this chapter, you will create scripted geometry in SketchUp. Often called computational geometry, this is an exciting current topic that allows you to produce 3D shapes and arrangements that are impossible (or at least hard) to create by hand. Scripting in SketchUp also allows you to automatize repetitive tasks or facilitate data exchange with text files.

If you are new to scripting (or coding), then this chapter can serve as a great general introduction. You will learn principles that are common to many scripting languages, and you will apply those to creating items in SketchUp’s 3D environment—items that you can even fabricate (using instructions from Chapter 6).

SketchUp Models In This Chapter:

Below are two of the models that you can explore interactively in your browser (click and drag to orbit):

View and download all models from this chapter on the 3D Warehouse.

Links In This Chapter:

Updated links will be listed here:

Download The Script Examples:

You can save on typing and download all Ruby scripts from this chapter as a ZIP archive.

Sample Videos From This Chapter:

You can access all Chapter 7 videos using the password from the book on Wiley’s companion site:

All Chapter 7 videos:

  • 0701: Fun with coding in SketchUp (for all ages) (included here)
  • 0702: Intro to coding with the Ruby Code Editor (included here)
  • 0703: Mapping an object onto a shell

Next Steps:

  • Check out my blog posts and tutorials in the Ruby category.

Discuss Your Work:

You can discuss Ruby scripting in SketchUp with me and other users on this site in the following group:

Scripting Group

Comment On This Chapter:

Use the form below to add any comments, tips, tricks etc. for this chapter…

3 responses to Chapter 7 – Creating Geometry Using Ruby Scripting

  1. For code efficiency, don’t use the “typename” method when you are checking entities. Use this:
    someentity.is_a? Sketchup::Face

    instead of this:
    someentity.typename == "Face"

  2. A reader pointed out that the following line of code raises an error In the editor:

    new_length = "2'6".to_l

    This quirk goes away if you do something with the variable as in:

    new_length = "2'6".to_l
    p new_length

    I’ll look into this when I update the code editor next.

  3. A reader has pointed out that it may be hard to distinguish between commas and periods in the code listings in the book. To avoid any confusion, download the script examples from the link above.

Leave a reply

You must be logged in to post a comment.