Custom path for LM.GUI.OpenFile?
Moderators: Víctor Paredes, Belgarath, slowtiger
-
- Posts: 69
- Joined: Thu Jan 24, 2019 3:52 am
Custom path for LM.GUI.OpenFile?
Hi I am using OpenFile and when I call the function it opens the file explorer with the last default path.
Is there any way to use OpenFile,
to open a specific path?
Is there any way to use OpenFile,
to open a specific path?
- synthsin75
- Posts: 10266
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: Custom path for LM.GUI.OpenFile?
No, all of Moho defaults to the last directory.
The CurrentDirectory is stored in the user.settings file in AppData, but even changing that doesn't change where Moho opens the dialog.
That only changes when you actually open something in Moho. So Moho must have some internal, inaccessible place it stores the last directory.
I've even tried opening files using other scripting commands, like FileOpen, FileImport, SetSourceImage. But none change the current directory.
The CurrentDirectory is stored in the user.settings file in AppData, but even changing that doesn't change where Moho opens the dialog.
That only changes when you actually open something in Moho. So Moho must have some internal, inaccessible place it stores the last directory.
I've even tried opening files using other scripting commands, like FileOpen, FileImport, SetSourceImage. But none change the current directory.
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
-
- Posts: 69
- Joined: Thu Jan 24, 2019 3:52 am
Re: Custom path for LM.GUI.OpenFile?
synthsin75 wrote: ↑Sun Jan 29, 2023 1:50 am A I see, thanks for the answer.
I will try to look for some external lua code on the web to see if I can find something.
Re: Custom path for LM.GUI.OpenFile?
The other thing I wish it had - is the ability to specify the listed file spec. i.e. *.jpg,*.png
Moho 14.3 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.3 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam
Sam
Moho 14.3 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam
Sam
- synthsin75
- Posts: 10266
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: Custom path for LM.GUI.OpenFile?
Depending on what you want to do, you could basically create your own open dialog.
You'd start by using moho:BeginFileListing(dir, listHiddenAndSystemFiles), so you could specify the directory.
You'd do a loop of moho:GetNextFile() to make a list of files, which you could then edit for one or more specific extensions.
Then you'd have to present those choices to the user and open the selected one/s using FileOpen, FileImport, SetSourceImage, etc..
So maybe not too bad a workaround.
You'd start by using moho:BeginFileListing(dir, listHiddenAndSystemFiles), so you could specify the directory.
You'd do a loop of moho:GetNextFile() to make a list of files, which you could then edit for one or more specific extensions.
Then you'd have to present those choices to the user and open the selected one/s using FileOpen, FileImport, SetSourceImage, etc..
So maybe not too bad a workaround.
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
-
- Posts: 69
- Joined: Thu Jan 24, 2019 3:52 am
Re: Custom path for LM.GUI.OpenFile?
It would be great to create a custom directory.
I have seen your Switch Icons script, would it be something like this ?
Put images in a dialog box and select according to moho:GetNextFile().
Or perhaps a file explorer could be created.
I have seen your Switch Icons script, would it be something like this ?
Put images in a dialog box and select according to moho:GetNextFile().
Or perhaps a file explorer could be created.
Re: Custom path for LM.GUI.OpenFile?
That would not work for general any user file browsing, as it requires the path to be known. I would also have to contend with the lack of sorting, additional filtering, file info etc. and the inability to preview thumbnails etc.synthsin75 wrote: ↑Sun Jan 29, 2023 8:25 am Depending on what you want to do, you could basically create your own open dialog.
You'd start by using moho:BeginFileListing(dir, listHiddenAndSystemFiles), so you could specify the directory.
You'd do a loop of moho:GetNextFile() to make a list of files, which you could then edit for one or more specific extensions.
Then you'd have to present those choices to the user and open the selected one/s using FileOpen, FileImport, SetSourceImage, etc..
So maybe not too bad a workaround.
Moho 14.3 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.3 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam
Sam
Moho 14.3 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam
Sam
- hayasidist
- Posts: 3841
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: Custom path for LM.GUI.OpenFile?
at the risk of sounding dumb -- are you opening a file using LM.GUI.OpenFile(caption) or ScriptInterface:FileOpen(path) or Lua's io.open (filename [, mode]) .. and would a different call give you what you want?bbrraayyaann wrote: ↑Sun Jan 29, 2023 12:44 am Hi I am using OpenFile and when I call the function it opens the file explorer with the last default path.
Is there any way to use OpenFile,
to open a specific path?
-
- Posts: 69
- Joined: Thu Jan 24, 2019 3:52 am
Re: Custom path for LM.GUI.OpenFile?
Yes, I am using LM.GUI.OpenFile(caption),
I am creating a script for a switch layer, and I have added an option to directly import an image or moho file directly to the switch, and when using that function I would need a specific path to save time.
Re: Custom path for LM.GUI.OpenFile?
Something like "moho:SetLastDir()" or "moho:SetOpenDir()" sounds to me like a perfectly reasonable feature request that I'm sure would have been added if someone had thought about it (I wish!) when the other ones (AppDir, UserAppDir, etc) was added. But it's never too late, I guess...bbrraayyaann wrote: ↑Sun Jan 29, 2023 12:44 am Hi I am using OpenFile and when I call the function it opens the file explorer with the last default path.
Is there any way to use OpenFile,
to open a specific path?
And that would be definitely like the icing on the cake.
So the only workaround (to call it something

Code: Select all
moho:CopyText("D:\\Projects\\Moho\\Moho Pro\\Scripts\\Menu")
Last edited by Rai López on Sun Jan 29, 2023 9:42 pm, edited 2 times in total.
...
-
- Posts: 69
- Joined: Thu Jan 24, 2019 3:52 am
Re: Custom path for LM.GUI.OpenFile?
Ramón López wrote: ↑Sun Jan 29, 2023 6:21 pm Yes, that's exactly what I was thinking ...
Before calling Open file copy the path to the clipboard, although you could also put a quick access in Windows. But if the quick access is full it would be useful to copy the path to the clipboard first.
It would still be good to put that function, I think it is not so difficult and also as SimplSam says, the option to only specify what type of files are allowed would be more complete.
Pd: I just saw the CopyText() thing, I thought it did not exist.
- synthsin75
- Posts: 10266
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: Custom path for LM.GUI.OpenFile?
Yeah, the OP needed to open a specific directory.SimplSam wrote: ↑Sun Jan 29, 2023 3:00 pmThat would not work for general any user file browsing, as it requires the path to be known. I would also have to contend with the lack of sorting, additional filtering, file info etc. and the inability to preview thumbnails etc.synthsin75 wrote: ↑Sun Jan 29, 2023 8:25 am Depending on what you want to do, you could basically create your own open dialog.
You'd start by using moho:BeginFileListing(dir, listHiddenAndSystemFiles), so you could specify the directory.
You'd do a loop of moho:GetNextFile() to make a list of files, which you could then edit for one or more specific extensions.
Then you'd have to present those choices to the user and open the selected one/s using FileOpen, FileImport, SetSourceImage, etc..
So maybe not too bad a workaround.
You could sort the results, like when you edit for extensions, before offering them to the user.
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
- hayasidist
- Posts: 3841
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: Custom path for LM.GUI.OpenFile?
try this (windows):
that will give you all the .pngs in that directory in a string with each entry delimited by new line; or use *l in a loop to get each line (nil on EoF). see http://www.lua.org/manual/5.2/manual.html#6.8
you could then use the filenames in a drop down to choose which one(s) to include or whatever....
Code: Select all
local path = "D:\\Projects\\Moho\\Moho Pro\\Scripts\\Menu\\"
local sOut = io.popen( "dir /B " .. path .. "*.png", "r" )
local sData = sOut:read "*a"
-- print sData
you could then use the filenames in a drop down to choose which one(s) to include or whatever....
-
- Posts: 69
- Joined: Thu Jan 24, 2019 3:52 am
Re: Custom path for LM.GUI.OpenFile?
How would it work exactly?hayasidist wrote: ↑Mon Jan 30, 2023 10:37 am try this (windows):
that will give you all the .pngs in that directory in a string with each entry delimited by new line; or use *l in a loop to get each line (nil on EoF). see http://www.lua.org/manual/5.2/manual.html#6.8Code: Select all
local path = "D:\\Projects\\Moho\\Moho Pro\\Scripts\\Menu\\" local sOut = io.popen( "dir /B " .. path .. "*.png", "r" ) local sData = sOut:read "*a" -- print sData
you could then use the filenames in a drop down to choose which one(s) to include or whatever....
Does sOut return a path or string?
- hayasidist
- Posts: 3841
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: Custom path for LM.GUI.OpenFile?
if you read using "*a" you get it all in one go as a string of the form of abc.png <newline> def.png <newline> etc. ;
if you read in a loop using "*l" you get each filename as a string on each call
if you want to use the names in ImageLayer:SetSourceImage(path) - concatenate filepath and filename
if you read in a loop using "*l" you get each filename as a string on each call
if you want to use the names in ImageLayer:SetSourceImage(path) - concatenate filepath and filename