Adding Realism by Randomizing

Add a touch of realism to your InfraWorks 360 models by randomizing the look of objects. The Javascript below will rotate selected city furniture objects about their Z axis at a random degree. The code below can be modified to limit the range of random values, adjust the Y translation value or any other number of settings. It can also be modified to work for other objects such as trees or points of interest.

See this article for more information regarding the other categories you can access in InfraWorks 360.

function RandomizeObjects() {
    var db = app.ActiveModelDb;
    var sset = app.ActiveSelectionSet;
    var tableName = "CITY_FURNITURE";
    // You must have at least one object selected
    if (sset.QueryCount() < 1) {
        alert("Please select one or more " + tableName + " objects and try again.");
    var filter = sset.GetFilter(db.TableIndex(tableName));
    var table = db.Table(tableName);
    var extent = table.QueryExtent(filter);
    var read;
    var write = table.GetWriteRow();
    while (read = table.Next()) {
        // parseInt((Math.random() * (max - min + 1)), 10) + min;
        // Rotate the object about the Z axis using a max value (95) and a min value (85)
        // Adjust the min/max values to suit your needs.
        write.MODEL_ROTATE_Z = parseInt((Math.random() * (95 - 85 + 1)), 10) + 85;
        // Randomize the Translate Y value between 0.25 (max value) and -0.25 (min value)
        write.MODEL_TRANSLATE_Y = parseInt((Math.random() * (0.25 - -0.25 + 1)), 10) + 0;
        table.UpdateFeature(write, read.ID);
    app.InvalidateTileCache(db.TableIndex(tableName), extent);
    return true;


Autodesk Screencast video demonstrating the use of the Javascript code to randomize objects in an InfraWorks 360 model.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s