# Script.loadResources syntax & modules & new script IDE

**URL:** <https://resource.dopus.com/t/script-loadresources-syntax-modules-new-script-ide/48227>\
**Category:** Help & Support\
**Created:** [January 24, 2024, 9:47pm UTC](https://resource.dopus.com/t/script-loadresources-syntax-modules-new-script-ide/48227 "2024-01-24T21:47:06Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyilmaz](https://resource.dopus.com/user_avatar/resource.dopus.com/cyilmaz/32/51438_2.png) [@cyilmaz](https://resource.dopus.com/u/cyilmaz)\
**Post date:** [January 24, 2024, 9:47pm UTC](https://resource.dopus.com/t/script-loadresources-syntax-modules-new-script-ide/48227/1 "2024-01-24T21:47:06Z")

</div>

3 questions:

1. I'm trying to figure out how to call Script.loadResources with an XML string. [Help states](https://docs.dopus.com/doku.php?id=reference:scripting_reference:scripting_objects:script):

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

So I've tried these

```auto
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](https://resource.dopus.com/t/can-dialogs-be-dynamic/43734/8) 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](https://docs.dopus.com/doku.php?id=scripting:script_add-ins:modules) 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.

---

<div class="post-metadata">

**Author:** ![galaxyhub](https://resource.dopus.com/user_avatar/resource.dopus.com/galaxyhub/32/42793_2.png) [@galaxyhub](https://resource.dopus.com/u/galaxyhub)\
**Post date:** [January 25, 2024, 5:11am UTC](https://resource.dopus.com/t/script-loadresources-syntax-modules-new-script-ide/48227/2 "2024-01-25T05:11:56Z")

</div>

> [@cyilmaz](#):
>
> 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

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

---

<div class="post-metadata">

**Author:** ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)\
**Post date:** [January 25, 2024, 5:42am UTC](https://resource.dopus.com/t/script-loadresources-syntax-modules-new-script-ide/48227/3 "2024-01-25T05:42:28Z")

</div>

> [@cyilmaz](#):
>
> how to call Script.loadResources with an XML string

Try starting your script with

```javascript
Script.LoadResources('CuTokenizerDialogs.xml');

```

---

<div class="post-metadata">

**Author:** ![cyilmaz](https://resource.dopus.com/user_avatar/resource.dopus.com/cyilmaz/32/51438_2.png) [@cyilmaz](https://resource.dopus.com/u/cyilmaz)\
**Post date:** [January 25, 2024, 7:33am UTC](https://resource.dopus.com/t/script-loadresources-syntax-modules-new-script-ide/48227/4 "2024-01-25T07:33:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)\
**Post date:** [January 25, 2024, 8:05am UTC](https://resource.dopus.com/t/script-loadresources-syntax-modules-new-script-ide/48227/5 "2024-01-25T08:05:21Z")

</div>

Did you prefix this with `var x1 = `?

`LoadResources()` doesn't return anything.

The .XML should start with `<resources>`

---

<div class="post-metadata">

**Author:** ![cyilmaz](https://resource.dopus.com/user_avatar/resource.dopus.com/cyilmaz/32/51438_2.png) [@cyilmaz](https://resource.dopus.com/u/cyilmaz)\
**Post date:** [January 25, 2024, 8:33am UTC](https://resource.dopus.com/t/script-loadresources-syntax-modules-new-script-ide/48227/6 "2024-01-25T08:33:57Z")

</div>

> [@lxp](#):
>
> Did you prefix this with `var x1 = `?

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

> [@lxp](#):
>
> The .XML should start with `<resources>`

It does.

 ![image](https://resource.dopus.com/uploads/default/original/3X/f/e/fed3efd25f88bf62e12621c7d279289e2911f222.png)

---

<div class="post-metadata">

**Author:** ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)\
**Post date:** [January 25, 2024, 8:42am UTC](https://resource.dopus.com/t/script-loadresources-syntax-modules-new-script-ide/48227/7 "2024-01-25T08:42:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [January 25, 2024, 8:48am UTC](https://resource.dopus.com/t/script-loadresources-syntax-modules-new-script-ide/48227/8 "2024-01-25T08:48:17Z")

</div>

Not something I've used yet myself yet, but the top of [Script [Directory Opus Manual]](https://docs.dopus.com/doku.php?id=reference:scripting_reference:scripting_objects:script) 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](https://docs.dopus.com/doku.php?id=reference:scripting_reference:scripting_events:onaddcommands)** or **[OnAddColumns](https://docs.dopus.com/doku.php?id=reference:scripting_reference:scripting_events: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.)

---

<div class="post-metadata">

**Author:** ![cyilmaz](https://resource.dopus.com/user_avatar/resource.dopus.com/cyilmaz/32/51438_2.png) [@cyilmaz](https://resource.dopus.com/u/cyilmaz)\
**Post date:** [January 25, 2024, 9:03am UTC](https://resource.dopus.com/t/script-loadresources-syntax-modules-new-script-ide/48227/9 "2024-01-25T09:03:58Z")

</div>

> [@lxp](#):
>
> first in the `OnCommand()` function

> [@Leo](#):
>
> not in OnInit

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:

```auto
// 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! ❤

Any ideas on #2?

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [January 25, 2024, 9:17am UTC](https://resource.dopus.com/t/script-loadresources-syntax-modules-new-script-ide/48227/10 "2024-01-25T09:17:51Z")

</div>

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

![image](https://resource.dopus.com/uploads/default/original/3X/7/1/7191aa59776cd5f10dd98b316f5d8d2b36b8b844.png)

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

 ![image](https://resource.dopus.com/uploads/default/original/3X/4/0/40b33339172662547a7b8969f1c4c62568e32d89.png)

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

---

<div class="post-metadata">

**Author:** ![cyilmaz](https://resource.dopus.com/user_avatar/resource.dopus.com/cyilmaz/32/51438_2.png) [@cyilmaz](https://resource.dopus.com/u/cyilmaz)\
**Post date:** [January 25, 2024, 10:43am UTC](https://resource.dopus.com/t/script-loadresources-syntax-modules-new-script-ide/48227/11 "2024-01-25T10:43:59Z")

</div>

> [@Leo](#):
>
> if the script is in a .OSP package

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](https://docs.dopus.com/doku.php?id=scripting:script_add-ins:modules&s%5B%5D=script&s%5B%5D=module)

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

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [January 25, 2024, 11:34am UTC](https://resource.dopus.com/t/script-loadresources-syntax-modules-new-script-ide/48227/12 "2024-01-25T11:34:51Z")

</div>

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.
