Caffeine Abuse - The Blog

Replace object A with a random new object

You’ve spent countless nights trying to finish the project on time and you’re just about to hit that sweet render button when the brilliant client comes through the door. He has just decided that he doesn’t want the landscape of cubes any more; he wants a random mixture of spheres, orbs and globs. Then he leaves you with the inspiring task of replacing the whole scene. A scenario that sadly isn’t all that uncommon. Though there’s no need to despair, with the solution below you should be home long before bedtime.


Open the scene spheres.scn from this issues CD. Press [Alt] + [4] to open the Script Editor and from the File menu choose Preferences… Change the Scripting Language to JScript and check the Log Commands checkbox. Close the PPG. Now, let’s have a quick look at the ingredients that you’ll be using in the script. Select an object, press [Ctrl] + [D] to create a duplicate, from the MCP > Transform menu choose Match All Transforms and pick any object. Then press [Del] to delete it. The script editor has just logged all the commands you need. The next step is to add which objects to replace, which objects that will be used to replace them and a random function that will choose one of these objects. The final script will look like this.


Since the script picks one of the three objects randomly, you can run the script again if you’re not happy with the distribution after the first run.
The project files used in this tutorial can be found at:
Quick tip
Change the Duplicate command to Clone (or Instantiate if you’re using models) to create clones of the replacing objects instead of duplicates.


  1. June 29, 2009

    May you upload a larger picture of the script? Thanks!

  2. July 2, 2009

    Hi Ray,

    I have no idea why you can’t click on that specific image to get a larger version of it… but I’ll look into it ASAP. In the meantime please send me an email with your address and I’ll send you the image…


  3. July 6, 2009

    Hey Ola,
    You got really nice blog! Thanks!

  4. June 5, 2010

    Yeah I can’t see the larger script either. My email is