Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem accessing unitsManager

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
billoverman
384 Views, 5 Replies

Problem accessing unitsManager

I have a very short script program (js) that won't run or debug.

 

I've narrowed it down to a call to design.unitsManager. If I comment out the line below where I'm trying to get the unitsManager, everything works fine. I can even evaluate in the console and see that design.unitsManager is indeed a fusionUnitsManager.

 

However, if the line is as shown (i.e., not commented out) Chrome doesn't launch at all. In Fusion I see the spinning dots in the list of Scripts next to my script name (and the Stop button is enabled).

 

This seems to follow the example program for UnitsManager.

 

Any ideas?

 

//Author-
//Description-

function run(context) {

    "use strict";
    if (adsk.debug === true) {
        /*jslint debug: true*/
        debugger;
        /*jslint debug: false*/
    }
 
    var ui;
    try {
        var app = adsk.core.Application.get();
        ui = app.userInterface;
 
        var doc = app.activeDocument;
        var product = app.activeProduct;
        var design = adsk.fusion.Design(product);
        var rootComp = design.rootComponent;
        var eval = design.unitsManager;  // ============ this is the line that doesn't work

    } 
    catch (e) {
        if (ui) {
            ui.messageBox('Failed : ' + (e.description ? e.description : e));
        }
    }

    adsk.terminate(); 
}
5 REPLIES 5
Message 2 of 6
zhijie.li
in reply to: billoverman

The problem is caused by the variable name "eval" which is the built-in function of JavaScript. Changing the name will solve the problem.

Message 3 of 6
liujac
in reply to: billoverman

Hi,

 

You need to change the variable name "eval" to another one. Because eval is a function of JavaScript. The code below should work.

 

var eva = design.unitsManager; 

 

Jack

 

Message 4 of 6
billoverman
in reply to: zhijie.li

I thought of that and tried a bogus variable name. I also tried inlining the
expression everywhere I used it. No change in behavior.
Message 5 of 6
zhijie.li
in reply to: billoverman

You mean by changing the variable name, the issue still exists? I tried to run it locally, but it works fine. Can you try the following code again? If the problem still exists, please zip your script(include html, js, manifest) and post it as attachment, so we can investigate if there is any other issue.

 

//Author-
//Description-

function run(context) {

    "use strict";
    if (adsk.debug === true) {
        /*jslint debug: true*/
        debugger;
        /*jslint debug: false*/
    }
 
    var ui;
    try {
        var app = adsk.core.Application.get();
        ui = app.userInterface;
 
        var doc = app.activeDocument;
        var product = app.activeProduct;
        var design = adsk.fusion.Design(product);
        var rootComp = design.rootComponent;
        var eval_ = design.unitsManager;  // ============ this is the line that doesn't work

    } 
    catch (e) {
        if (ui) {
            ui.messageBox('Failed : ' + (e.description ? e.description : e));
        }
    }

    adsk.terminate(); 
}

 Another thing is if the script is still running QQ图片20160222104018.png, please stop it, before debuging or running.

Message 6 of 6
billoverman
in reply to: zhijie.li

Thanks. That worked.

 

I thought I had done exactly what you suggested, but apparently not.

 

Bill

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report