Problem accessing unitsManager

Problem accessing unitsManager

billoverman
Participant Participant
656 Views
5 Replies
Message 1 of 6

Problem accessing unitsManager

billoverman
Participant
Participant

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(); 
}
0 Likes
Accepted solutions (2)
657 Views
5 Replies
Replies (5)
Message 2 of 6

zhijie.li
Alumni
Alumni
Accepted solution

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

0 Likes
Message 3 of 6

liujac
Alumni
Alumni
Accepted solution

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

 

0 Likes
Message 4 of 6

billoverman
Participant
Participant
I thought of that and tried a bogus variable name. I also tried inlining the
expression everywhere I used it. No change in behavior.
0 Likes
Message 5 of 6

zhijie.li
Alumni
Alumni

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.

0 Likes
Message 6 of 6

billoverman
Participant
Participant

Thanks. That worked.

 

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

 

Bill

0 Likes