Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: yonatan.lehman on June 27, 2022, 10:56:44 pm

Title: How to get the user to select a folder from a JS script (EA14)
Post by: yonatan.lehman on June 27, 2022, 10:56:44 pm
Hi
I can ask the user to select a file using Repository.InvokeFileDialog  or use DLGOpenFile from EAScriptLBi.JScript-Dialog.

How do I open a dialog that allows the user to select (or create) a directory (folder)?
I know almost nothing about VB - so a good example in JS, or can be converted to JS would be great!

Thanks
Title: Re: How to get the user to select a folder from a JS script (EA14)
Post by: Geert Bellekens on June 27, 2022, 11:20:44 pm
I only use VBScript, so this is what I use in a class called FileSystemFolder: https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Framework/Utils/FileSystemFolder.vbs (https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Framework/Utils/FileSystemFolder.vbs)

Code: [Select]
'let the user select a folder, optionally from a given starting path.
public function getUserSelectedFolder(startPath)
dim folder, shell
Set shell  = CreateObject( "Shell.Application" )
if len(startPath) > 0 then
Set folder = shell.BrowseForFolder( 0, "Select Folder", 0,startPath)
else
Set folder = shell.BrowseForFolder( 0, "Select Folder", 0)
end if
if not folder is nothing then
set getUserSelectedFolder = New FileSystemFolder
getUserSelectedFolder.FullPath = folder.Self.Path
Session.Output "folder.Self.Path: " & folder.Self.Path
else
set getUserSelectedFolder = Nothing
end if
end function


I hope this helps. I guess you should be able to translate that to JS pretty easily.

Geert
Title: Re: How to get the user to select a folder from a JS script (EA14)
Post by: yonatan.lehman on June 28, 2022, 12:30:48 am
Cheers !
Title: Re: How to get the user to select a folder from a JS script (EA14)
Post by: yonatan.lehman on June 28, 2022, 12:42:41 am
Based on JScript-Dialog
the VB equivilent of
   set openFileDialog = CreateObject("MSComDlg.CommonDialog")
is
  var openFileDialog = new ActiveXObject("MSComDlg.CommonDialog");

But when I do this (as a 1st step before trying to change it to "Shell.Application")
I get an Error Dialog:

Automation server can't create object


I guess I need to set some permission - but how ?