Getting Fusion object in flexible web layout

By Daniel Du

When developing with flexible web layout, we always need to get the global object Fusion. Sometimes you may get error message: ' Fusion is undefined' if you do not get it correctly.

Actually, how to get the Fusion object depends on how you embed the fusion viewer into your webpage and where you call your JavaScript to get it. Generally speaking, if you are not using <frame> or <iframe> when embedding fusion viewer, following code snippet should work for you.

var MainFusionWindow = GetFusionWindow();
var OpenLayers = MainFusionWindow.OpenLayers;
var Fusion = MainFusionWindow.Fusion;
 
alert(Fusion);
 
 
 
/* locate the Fusion window */
function GetFusionWindow() {
    var curWindow = window;
    while (!curWindow.Fusion) {
        if (curWindow.parent && curWindow != curWindow.parent) {
            curWindow = curWindow.parent;
        } else if (curWindow.opener) {
            curWindow = curWindow.opener;
        } else {
            alert('Could not find Fusion instance');
            break;
        }
    }
    return curWindow;
}

Hope this helps.


Comments

3 responses to “Getting Fusion object in flexible web layout”

  1. Hi,
    How do you properly set fusion’s config.json? We are currently implementing flexible web layout but we’re having issues in utilizing FUSION’s API because of the current setup defined in config.json. We’re getting an error message “Error loading configuration file, initialization aborted. Make sure you have copied config_dist.json to config.json and have configured the settings for your system.”
    Note: config_dist.json is already named as config.json
    Hope to hear from you soon. Thank you very much.

  2. Hi Arrianne,
    I did not do anything with config.json, just using the default one which is installed by installer. I don’t think it is necessary to modify this file except you have particular needs.

  3. Hi Daniel,
    Thank you very much for the quick reply. I imported fusion.js and when I try to run the application, I’m getting the error message “Error loading configuration file, initialization aborted. Make sure you have copied config_dist.json to config.json and have configured the settings for your system.” What may be the possible cause for having such kind of error?
    Again, thank you very much.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading