Batch Create Snapshots from InfraWorks using JavaScript - Part I
Matt Wunch
Connecting the dots between ideas, people, and technology to make a real difference!
Did you know you can automate workflows in InfraWorks using JavaScript? It's true!!
Using a few lines of?JavaScript?code?you can automate the process of creating snapshots for each bookmark in your model.
To run the code simply open the SCRIPTING?editor and?copy/paste the code below into the main window then click the START SCRIPT button and the code will loop through the bookmarks of the current model and create a snapshot for each one. You can modify the length, width and location of the snapshots by modifying the variables in the code below. The snapshots that are created have the same?name?as their corresponding?bookmarks.
领英推荐
// Some global variables...
var doc = app.ActiveDocument(); // the Active Document
var bmList = ?app.ActiveDocument().Bookmarks; // a variable to hold the list of bookmarks
var imgWidth = 1920; // snapshot width in pixels. change to your preference
var imgHeight = 1080; // snapshot height in pixels. change to your preference
// Loop through the bookmarks within the model
for (var?i=0;?i<bmList.length;?i++)?{
var?bm?=?bmList[i]; // list of bookmarks
var strFilePath = "C:\\temp\\"; // Change this path to where you want your snapshots saved
var bName = (bm.name); //gets the bookmark name
var bmName = (bm.name+".jpg"); // appends .JPG to the bookmark name
strFilePath = strFilePath + bmName; // concatenate the string of the path (from above) and the bookmark name with .JPG
CreateBookmarkSnapshot (bName, strFilePath); // pass the bookmark's name and concatenated file path/name to the CreateBookmarkSnapshot function
}
// Create a snapshot of the active bookmark
function CreateBookmarkSnapshot (strBookMarkName, strJPGPath) {
doc.MoveToBookmark(strBookMarkName); // activate the bookmark
app.CreateSnapshot(strJPGPath, imgWidth, imgHeight); // create the snapshot using the defined path/name and width & height variables
}
Curious to learn more?
Connect with me or subscribe to the Built Different newsletter for more insights on leveraging automation in AEC. You can also book some time with me to discuss how Autodesk Construction Cloud can help your team streamline your workflows and unlock the full potential of your project data.