lenght of a curve

 From:  Michael Gibson
5205.4 In reply to 5205.3 
Hi nos - an inline script like that executes inside of its own individual script context, it's not inside of an actual HTML document when run in that way so global variables like "document" which are part of the HTML environment are not in there. But there is a global variable "moi" set for all script contexts and you can access the MoI object model through that and one of the things you can do through there is find one of the UI Panels which does have HTML in it and then interact with that.

I think you're trying to copy some code from the "CurveLengthBeingDrawn" script? The difference is that other script injects its script code into a HTML document by the first part of the script: moi.ui.commandUI.setInterval( 'script code in here' ); - that's why it works in that case to access stuff like document.body since the code is running in a timer handler there and the script context which the timer hander is running in is one that comes from an HTML page and so it has the HTML environment in it with stuff like "document", etc... in it.

The moi.ui.commandUI document is the document that holds the content for the options of the current running command - it's only actually visible on screen while a command is running.

You can get the HTML window object of the UI panels by calling moi.ui.getUIPanel('panel url') - like for example: moi.ui.getUIPanel('moi://ui/CommandBar.htm') will get you the HTML window for the bottom toolbar, you could then call document.body.insertAdjacentHTML() on that to inject HTML that will show up in the bottom toolbar.

So anyway things like "document" are not actually part of raw JavaScript itself, those things are added by the HTML environment and so they're only there for script contexts that are created as part of an HTML frame instance.


> And whats the catch(e) for, is it needed?

The catch(e) was needed for the "CurveLengthBeingDrawn" script to conclude the try { } block - you don't need that in your case since you have different code than that the "CurveLengthBeingDrawn" script and yours does not set up a try { } block in the start of it.

- Michael