Snapshot Multiple Bookmarks and Proposals

Snapshot Multiple Bookmarks and Proposals

kwilktrihydro
Advocate Advocate
2,214 Views
13 Replies
Message 1 of 14

Snapshot Multiple Bookmarks and Proposals

kwilktrihydro
Advocate
Advocate

Hi there, 

 

I have a design where we need to show the client 3 different options and the existing site. I have designed each of these as separate proposals in Infraworks. I then have 7 bookmarks (viewpoints) that the client would like me to create snapshots from. 

 

Does anyone know of anyway to automate the creation of these snapshots? Maybe a script? I don't want to go through and create 28 different snapshots each time the client wants to change the design. 

 

Thanks in advance for any help or advice!

 

Kelby

Kelby Wilkison, P.E.
Civil Engineer
Trihydro Corporation
0 Likes
Accepted solutions (2)
2,215 Views
13 Replies
Replies (13)
Message 2 of 14

Glenn.Coppard
Advocate
Advocate

Easily done using scripts, example to get you started HERE by Matt Wunch.

 

@Anonymous  also outlines some of the process he used combining the above  HERE

Message 3 of 14

Glenn.Coppard
Advocate
Advocate

You will probably also what to look at this post HERE from @Matt__W  (again 😉 ) and @elliott.rosenfeld 

Message 4 of 14

Matt__W
Advisor
Advisor

I should probably write a new script that cycles through each proposal and snapshots each bookmark.  😁



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

Message 5 of 14

kwilktrihydro
Advocate
Advocate

Wow, thank you both for your input.  @Glenn.Coppard  I really appreciate the links! I will definitely take a look at these files and see what I can do! Sorry it took me so long, I got taken over by another project.

 

@Matt__W  if you do end up revising your script, definitely let me know. If not, it looks like you have done most of the lifting, and I have been meaning to dive into the world of Infraworks scripting anyway. 

 

Kelby

Kelby Wilkison, P.E.
Civil Engineer
Trihydro Corporation
0 Likes
Message 6 of 14

Matt__W
Advisor
Advisor

@kwilktrihydro the new code is already underway and should be done soon (next few days, give or take, depending on the Thanksgiving holiday break).



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

Message 7 of 14

Glenn.Coppard
Advocate
Advocate

@Matt__W  sounds good to get the non-script savvy going in a brute-force fashion.

We generally structure our Bookmark Naming to the Proposal (or general) and then loop through the Proposals and output the relevant 'prefixed' bookmarks for that option and files named accordingly.

Saves a lot of time filtering through un-necessary JPG files....

 

There a few more hints/tips for you @kwilktrihydro  don't forget to accept the solution - will help others find the info in the future - good luck. [edit] OK - looks like that 'button' is MIA these days - O'well[/edit]

Message 8 of 14

Matt__W
Advisor
Advisor

Alright.... here you go.

 

This will cycle through each proposal and create a snapshot for each bookmark. Enjoy.

(I guess now I have to write up a new AKN article for this.)  😁

// get the active document
var doc = app.ActiveDocument();
// get all of the bookmarks in zsthe active document
var bmList = app.ActiveDocument().Bookmarks;
// Get all proposals in the model, cycle through them & print them to the debug panel
var varProps = doc.GetAllProposals("");
// image width
var imgWidth = 1920;
// image height
var imgHeight = 1080;

for (x in varProps) {
    var propName = (varProps[x]);
    doc.ChangeProposal(varProps[x]);
    for (var i=0; i<bmList.length; i++) {
        var bm = bmList [i];
        doc.MoveToBookmark(bm.name);
        // location to save snapshots
        var strFilePath = "C:\\Snapshots\\";
        // bookmark name
        var bName = (propName+"-"+bm.name);
        //file name (prefix + bookmark name + .JPG extension
        var bmName = (bName+".jpg");
        // complete output path and filename
        strFilePath = strFilePath + bmName;
        // create the snapshot
        app.CreateSnapshot(strFilePath, imgWidth, imgHeight);
    }
}


Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

Message 9 of 14

Matt__W
Advisor
Advisor
Accepted solution

Here's a new AKN article for batch snapshotting all bookmarks and all proposals. It also includes a link to download the JS code.

 

https://knowledge.autodesk.com/community/article/273056



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

Message 10 of 14

Anonymous
Not applicable

Hi,

I'm not that familiar with javascripts, but I think I'm doing something wrong. 

I got this message:

error.PNG

0 Likes
Message 11 of 14

srksphillips
Advocate
Advocate

I'm also unable to run any of these scripts in InfraWorks 20.0.25.0 (I am unwilling to upgrade after the trouble it caused last time). I have been able to run these script in the past on this build so not sure what's going on.

 

The debugger is not happy from the start:

 

var doc = app.ActiveDocument(); // the Active Document

 

If I run anyway I get:

 

There is no image format associated with the specified extension. Do you want to use JPEG format?

 

I have to get a ton of snapshots out soon and would appreciate any help.

 

Cheers,

Steve

0 Likes
Message 12 of 14

m_kingdon
Advisor
Advisor

Mike here from the future.  Do any of these scripts work?  I have the same problem but none of the links seem to work anymore after AutoDesk's brutal purge of the forum.

Mike Kingdon
Civil 3D Zealot

EESignature

0 Likes
Message 13 of 14

srksphillips
Advocate
Advocate
Accepted solution

Hello Mike from the future! 

This script creates 4K snapshots from your bookmarks for the current proposal only. It identifies the active proposal name and the bookmark names, then uses these values to name each snapshot. The files are saved in a folder called Snapshots on your C drive (C:\Snapshots). You will need to create this folder or change the path in the script to suit your setup.


The file path appears in the script as "C:\\Snapshots\\" rather than "C:\Snapshots". This is normal because the backslashes must be escaped in the code.


If you prefer HD images you can change the imgWidth and imgHeight values to 1920 and 1080.

 

// get the active document
var doc = app.ActiveDocument();
// get all of the bookmarks in the active document
var bmList = app.ActiveDocument().Bookmarks;
// image width
var imgWidth = 3840;
// image height
var imgHeight = 2160;

// Get the name of the currently active proposal
var activeProposal = doc.ActiveProposalName;

// Iterate through each bookmark in the active proposal
for (var i = 0; i < bmList.length; i++) {
    var bm = bmList[i];
    // Move to the bookmark
    doc.MoveToBookmark(bm.name);
    // location to save snapshots
    var strFilePath = "C:\\Snapshots\\";
    // bookmark name
    var bName = (activeProposal + "-" + bm.name);
    // file name (Proposal Name + Bookmark Name + .JPEG extension)
    var bmName = (bName + ".jpeg");
    // complete output path and filename
    strFilePath = strFilePath + bmName;
    // create the snapshot
    app.CreateSnapshot(strFilePath, imgWidth, imgHeight);
}

 

This is the same as above but iterates through all proposals except the Master. 

 

// get the active document
var doc = app.ActiveDocument();
// get all of the bookmarks in the active document
var bmList = app.ActiveDocument().Bookmarks;
// Get all proposals in the model
var varProps = doc.GetAllProposals("");
// image width
var imgWidth = 3840;
// image height
var imgHeight = 2160;

// iterate through each proposal
for (x in varProps) {
    var propName = (varProps[x]);
    // Check if the proposal is not the default "master" proposal
    if (propName !== "master") {
        // Activate a proposal
        doc.ChangeProposal(varProps[x]);
        // iterate through each bookmark
        for (var i=0; i<bmList.length; i++) {
            var bm = bmList[i];
            // Move to the bookmark
            doc.MoveToBookmark(bm.name);
            // location to save snapshots
            var strFilePath = "C:\\Snapshots\\";
            // bookmark name
            var bName = (propName + "-" + bm.name);
            // file name (Proposal Name + Bookmark Name + .JPEG extension)
            var bmName = (bName + ".jpeg");
            // complete output path and filename
            strFilePath = strFilePath + bmName;
            // create the snapshot
            app.CreateSnapshot(strFilePath, imgWidth, imgHeight);
        }
    }
}

 

This script generates text that lists all bookmark names together with detailed camera information for each one. The output includes coordinates, heading, tilt and roll. You can use this information to create a CSV file that can be imported as GIS data. This allows you to plot arrows that show the position and direction of each bookmark view.


After running the script, select the text in the output window and save it in Notepad as a CSV file.

 

print("Name,Lon,Lat,Elevation,X,Y,Z,Heading,Tilt,Roll");

var doc = app.ActiveDocument(); // Get the active document
var bmList = doc.Bookmarks;     // Retrieve the list of bookmarks

for (var i = 0; i < bmList.length; i++) {
    var bm = bmList[i];
    doc.MoveToBookmark(bm.name);

    var viewPoints = doc.GetCurrentViewPoint(); // [position, target, up]
    var pos = viewPoints[0];
    var target = viewPoints[1];

    // Convert LL84 to model coordinates (meters)
    var pos2d = new adsk.Vec2d(pos.X, pos.Y);
    var target2d = new adsk.Vec2d(target.X, target.Y);

    var posProjected = app.ReprojectPointLL84ToDb(pos2d);
    var targetProjected = app.ReprojectPointLL84ToDb(target2d);

    // Direction vector in model coordinates
    var dx = targetProjected.X - posProjected.X;
    var dy = targetProjected.Y - posProjected.Y;
    var dz = target.Z - pos.Z;

    // Heading (bearing from north, clockwise)
    var heading = (Math.atan2(dx, dy) * 180 / Math.PI + 360) % 360;

    // Tilt (pitch angle in degrees)
    var horizontalDistance = Math.sqrt(dx * dx + dy * dy);
    var tilt = Math.atan2(dz, horizontalDistance) * 180 / Math.PI;

    // Roll (assumed 0 unless known)
    var roll = 0;

    print(
        bm.name + "," +
        pos.X.toFixed(6) + "," +     // Longitude
        pos.Y.toFixed(6) + "," +     // Latitude
        pos.Z.toFixed(3) + "," +     // Elevation
        posProjected.X.toFixed(3) + "," + // X in meters
        posProjected.Y.toFixed(3) + "," + // Y in meters
        pos.Z.toFixed(3) + "," +     // Z in meters
        heading.toFixed(2) + "," +
        tilt.toFixed(2) + "," +
        roll.toFixed(2)
    );
}

 

Just to confirm that all the scripts above work exactly as expected. I have run them today and everything functions correctly.


Cheers,

Steve

0 Likes
Message 14 of 14

m_kingdon
Advisor
Advisor

Hi Steve, the code works great.  Cheers very much for your help!

Mike Kingdon
Civil 3D Zealot

EESignature