Script.loadResources syntax & modules & new script IDE

3 questions:

  1. I'm trying to figure out how to call Script.loadResources with an XML string. Help states:

You can either provide a filename or a raw XML string.

So I've tried these

var x1 = Script.loadResources('<resources><resource name="dlg1" type="dialog"><dialog fontsize="9" height="100" width="180" /></resource></resources>');
var x2 = Script.loadResources('/scripts/CuTokenizerDialogs.xml'); // this file exists
// I know .odxml is meant for script packages, this was a desparate attempt
var x3 = Script.loadResources('/scripts/CuTokenizerDialogs.odxml'); // this file exists
var x4 = Script.loadResources('C:\\Users\\cu\\AppData\\Roaming\\GPSoftware\\Directory Opus\\Script AddIns\\CuTokenizerDialogs.xml'); // same as above, full path
var x5 = Script.loadResources('C:\\Users\\cu\\AppData\\Roaming\\GPSoftware\\Directory Opus\\Script AddIns\\CuTokenizerDialogs.odxml'); // same as above, full path

But they all give an error. There's a single thread about this function. The OP's string was mistakenly multi-line which JS doesn't support but even if he had fixed it, that part of his question went unanswered and he went on to putting ==SCRIPT RESOURCES at the end of the .js. I'd rather not use it because both ESLint & VSCode TS-checker don't like such non-JS blocks. What is the right syntax for Script.loadResources() or is it buggy?

  1. So I tried to push the linter error out of sight by creating a CuTokenizer.js.Dialogs.osm and put the ==SCRIPT RESOURCES block in there, which didn't work. So I put pure JS code in it DOpus.output('hello'); which didn't work either. This works with inc_something.js right away, but not .osm. Help states the new IDE would let me create new modules so I hoped DOpus would create a proper one for me but I see no module-related option. How do we use .osm's?

  2. New editor has a setting "use external text editor", which I set to Visual Studio Code, but IDE just starts with a blank page then. It's easier for me to start VSC directly instead of going thru multiple DOpus screens (Prefs Scripts -> Edit) anyway but I wanted to let you know, something might not be right there.

I've also had this problem, not found a solution yet.

1 Like

Try starting your script with

Script.LoadResources('CuTokenizerDialogs.xml');
1 Like

Huh, I overlooked that variant :slight_smile: Unfortunately same error: "Object doesn't support this property or method (0x800a01b6)"

Did you prefix this with var x1 = ?

LoadResources() doesn't return anything.

The .XML should start with <resources>

I tried with and without. And the other variants as well. Still puzzled about the "raw XML" variant as well.

It does.

Try making the line the first in the OnCommand() function, not the first in the script.

1 Like

Not something I've used yet myself yet, but the top of Script [Directory Opus Manual] implies that the Script object won't exist until event handlers are called, and after (but not during) the OnInit event. So calling it at a global scope wouldn't work.

Calling it in OnAddCommands or OnAddColumns (if you're using them already), or in the handler for the command that opens the dialog, should work.

(Note that implementing those events mean the command/columns have to be added in those events, not in OnInit. Most new scripts should use them already but old ones may need the code moving out of OnInit.)

1 Like

Thank you both, you removed my major misunderstanding. The method is indeed very picky, it won't run in OnInit, or any other place. Script.vars and other fields are unavailable either. Self-note: careful about Script object

For anybody in future looking for it, this is the working code for both variants:

// the registered handler for the custom command
function OnEverythingSearch_Tokenized(cmdData) {
    var dlg;
    Script.loadResources('<resources><resource name="dlg1" type="dialog"><dialog fontsize="9" height="100" width="180" /></resource></resources>');
    dlg = DOpus.dlg();
    dlg.template = 'dlg1';
    dlg.show();
    Script.loadResources('CuTokenizerDialogs.xml');
    dlg = DOpus.dlg();
    dlg.template = 'newrootpathdlg';
    dlg.show();
}

Question #1 answered. Thank you guys! :heart:

Any ideas on #2?

1 Like

For #2, the IDE can create a module for you if the script is in a .OSP package:

image

If it's just a standalone script file, you can convert it to a package using the IDE:

(Or zip it up and rename the archive to .osp extension.)

1 Like

Oh, so it's not possible with plain .js files. Yes this worked, but it wasn't clear to me from the modules help section

Again for future reference for others:

  • Convert the .js via IDE to package: this deletes the original .js and creates an .osp
  • Add a module via IDE: this temporarily unpacks the .osp, adds a new .osm file and repackages the .osp

tl;dr: It is not possible to use .osm files with plain .js files

Seems that way. Or, at least, the IDE won’t make them for you. I haven’t checked if they work when made by hand yet.

1 Like