Adding Realism to your InfraWorks 360 Models by Randomizing
Editor’s note: This post was originally published on the The BIM Avenger's blog and re-published here with permission.
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.");
return;
}
var filter = sset.GetFilter(db.TableIndex(tableName));
var table = db.Table(tableName);
var extent = table.QueryExtent(filter);
table.StartQuery(filter);
table.BeginWriteBatch();
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);
write.Invalidate();
}
table.CommitWriteBatch();
table.EndQuery();
app.InvalidateTileCache(db.TableIndex(tableName), extent);
return true;
}
RandomizeObjects();
Click here to view an Autodesk Screencast video demonstrating the use of the Javascript code to randomize objects in an InfraWorks 360 model.
Editor’s note: This post was originally published on the The BIM Avenger's blog and re-published here with permission.
cover image © unsplash