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