Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: MatthiasVDE on September 13, 2022, 06:28:31 pm
-
I use this function to open a file, but now I want to adapt it to select a file or folder to save to. For that I need to change the script but I'm not familiar with those activeX stuf.
function selectFilePath()
dim wShell, oExec, sFileSelected
set wShell=CreateObject("WScript.Shell")
set oExec=wShell.Exec("mshta.exe ""about:[b]<input type=file id=FILE><script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>[/b]""")
sFileSelected = oExec.StdOut.ReadLine
selectFilePath = sFileSelected
end function
-
Seems like you are taking the complicated path. ???
This is the function I use in my FileSystemFolder utility class: https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Framework/Utils/FileSystemFolder.vbs
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
Geert
-
In vbscript its actually potentially even easier as the project interface provides this method:
Dim prj As EA.Project
Set prj = Repository.GetProjectInterface()
fullPath = prj.GetFileNameDialog (filename, "*.docx", 1, 0, "", 1) + ".docx"
-
In vbscript its actually potentially even easier as the project interface provides this method:
Dim prj As EA.Project
Set prj = Repository.GetProjectInterface()
fullPath = prj.GetFileNameDialog (filename, "*.docx", 1, 0, "", 1) + ".docx"
Yeah, that's OK for files, but not when you want your user to select a folder.
Geert
-
Seems like you are taking the complicated path. ???
This is the function I use in my FileSystemFolder utility class: https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Framework/Utils/FileSystemFolder.vbs
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
Geert
Hi Geert,
I used that one, but the UI is different and not easy to navigate.
-
There is an alternative call CommonOpenFileDialog, but I've only found references on how to use that using C#.
I'm not sure if you can use that from VBScript, but it might be worth a question in Stackoverflow to find out.
Geert
-
The following routine exports the contents of a note and saves it to a file.. in this case it is specific for PlantUML PUML files.. but it does prompt you for a folder.
https://github.com/gobravedave/Enterprise-Architect/blob/master/Diagram%20Scripts/Export-PlantUML-Script.vbs (https://github.com/gobravedave/Enterprise-Architect/blob/master/Diagram%20Scripts/Export-PlantUML-Script.vbs)
-
The following routine exports the contents of a note and saves it to a file.. in this case it is specific for PlantUML PUML files.. but it does prompt you for a folder.
https://github.com/gobravedave/Enterprise-Architect/blob/master/Diagram%20Scripts/Export-PlantUML-Script.vbs (https://github.com/gobravedave/Enterprise-Architect/blob/master/Diagram%20Scripts/Export-PlantUML-Script.vbs)
Do you mean the line
PlantUMLfn = project.GetFileNameDialog (currentDiagram.Name & ".puml", "PlantUML Files|*.pu;*.puml", 1, OFN_OVERWRITEPROMPT ,"", 1)
That will ask the user to select a (new or existing) file, not a folder. I don't think you can click on a folder and then OK, without having a filename in the filename field.
Geert
-
agree Geert.. you need a filename to save the file.
sorry I must of misunderstood the original question.
I want to adapt it to select a file or folder to save to.