Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started 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
-
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)
'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
-
Cheers !
-
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 ?