Including External vbScript Files in PowerDesigner

You can automate PowerDesigner by running vbScript directly or accessing the PD application objects from a COM aware language such as C# or VB. At this point I would like to keep everything simple and just run some vbScript from inside of the PowerDesigner Edit/Run Script console.

To really make some useful scripts in PowerDesigner you are going to want to leverage some shared code. This is easy in C# or VB but not so much in the basic vbScript environment. I can do most of what I want to do in vbScript but there is no obvious/simple way to include external files.

The PD documentation goes into a little detail about this topic in the Differences Between VBScript and OLE Automation section.

Here is a way to include a function and make it available in multiple script. Given a function called BrowseForFile that returns a string...

lib\BrowseForFile.vbs :

function BrowseForFile
... blah blah blah ...
end function

You can reference it at the top of a calling program and then call the function all that you like...

ExampleInclude.vbs :

executeGlobal CreateObject("Scripting.FileSystemObject").openTextFile("lib\BrowseForFile.vbs").readAll()

output BrowseForFile()

So just substitute your filename in the openTextFile call. You can call this multiple times to include more than 1 file. As best I can tell the path is relative from the current directory. I will be making some useful functions and more examples available in the near future.