3 Dec 2020
PixelCompare extension
Previously you needed a custom version of the PixelCompare extension in order to use it in your app - see Compare two 2D documents using Forge Viewer
Though it does not seem to be documented on the Forge website, we did provide information on the improvements it has been getting - see Viewer Release Notes: v 7.4
It's really simple to use.
You just have to load two sheets into the model (e.g. two single page PDF files) and call compareTwoModels() for those models.
I'm using this code to load my two sample PDF files from my computer - see result in picture on top
function launchViewer() {
var options = {
env: 'Local'
};
Autodesk.Viewing.Initializer(options, () => {
viewer = new Autodesk.Viewing.GuiViewer3D(
document.getElementById('forgeViewer'), {}
);
viewer.start();
// Load 2 sheets
viewer.loadModel('scissors1.pdf', {}, (model1) => {
viewer.loadModel('scissors2.pdf', {}, async (model2) => {
// Compare them
const pcExt = await viewer.loadExtension('Autodesk.Viewing.PixelCompare');
pcExt.compareTwoModels(model1, model2);
});
});
});
}
The above code could also be used to load a PDF directly (without it being translated to SVF, by relying on the PdfLoader) from any storage location including OSS (inc BIM 360 Docs, Fusion Team) by providing the URL to the file, e.g.
Note: if the file is on OSS then you'll also have to provide the getAccessToken option as well for the Initializer function
viewer.loadModel("https://developer.api.autodesk.com/oss/v2/buckets/my_bucket/objects/my.pdf", {}, async (model1) => {
// etc
Here is how you can find a file's storage location if it's stored in BIM 360 Docs or Fusion Team: Download a File
If you were trying to compare sheets in a Revit document (or a PDF that has been translated to SVF), then better to use Autodesk.Viewing.Document.load() and viewer.loadDocumentNode() instead:
function launchViewer() {
var options = {
env: "AutodeskProduction",
getAccessToken: getForgeToken
};
Autodesk.Viewing.Initializer(options, () => {
viewer = new Autodesk.Viewing.GuiViewer3D(
document.getElementById('forgeViewer'), {}
);
viewer.start();
Autodesk.Viewing.Document.load('urn:dXJuOm...', doc => {
var viewables = doc.getRoot().search(
{
type: "geometry",
role: "2d",
},
true
);
// Load 2 sheets
viewer.loadDocumentNode(doc, viewables[0]).then((model1) => {
viewer.loadDocumentNode(doc, viewables[1], { keepCurrentModels: true }).then(async (model2) => {
// Compare them
var pcExt = await viewer.loadExtension("Autodesk.Viewing.PixelCompare");
pcExt.compareTwoModels(model1, model2);
})
});
});
});
}