Custom path for LM.GUI.OpenFile?

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
bbrraayyaann
Posts: 68
Joined: Thu Jan 24, 2019 3:52 am

Custom path for LM.GUI.OpenFile?

Post by bbrraayyaann »

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?
User avatar
synthsin75
Posts: 10009
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Custom path for LM.GUI.OpenFile?

Post by synthsin75 »

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.
bbrraayyaann
Posts: 68
Joined: Thu Jan 24, 2019 3:52 am

Re: Custom path for LM.GUI.OpenFile?

Post by bbrraayyaann »

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.
User avatar
SimplSam
Posts: 1063
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Custom path for LM.GUI.OpenFile?

Post by SimplSam »

The other thing I wish it had - is the ability to specify the listed file spec. i.e. *.jpg,*.png
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
synthsin75
Posts: 10009
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Custom path for LM.GUI.OpenFile?

Post by synthsin75 »

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.
bbrraayyaann
Posts: 68
Joined: Thu Jan 24, 2019 3:52 am

Re: Custom path for LM.GUI.OpenFile?

Post by bbrraayyaann »

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.
User avatar
SimplSam
Posts: 1063
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Custom path for LM.GUI.OpenFile?

Post by SimplSam »

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.
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.
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
hayasidist
Posts: 3561
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Custom path for LM.GUI.OpenFile?

Post by hayasidist »

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?
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
Posts: 68
Joined: Thu Jan 24, 2019 3:52 am

Re: Custom path for LM.GUI.OpenFile?

Post by bbrraayyaann »

hayasidist wrote: Sun Jan 29, 2023 3:17 pm
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.
User avatar
Rai López
Posts: 2250
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: Custom path for LM.GUI.OpenFile?

Post by Rai López »

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?
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...

SimplSam wrote: Sun Jan 29, 2023 2:53 am The other thing I wish it had - is the ability to specify the listed file spec. i.e. *.jpg,*.png
And that would be definitely like the icing on the cake.

So the only workaround (to call it something :roll:) for the moment that I can think is to pass the desired path to clipboard, e. g. like this:

Code: Select all

moho:CopyText("D:\\Projects\\Moho\\Moho Pro\\Scripts\\Menu")
Just before calling LM.GUI.OpenFile(), so that you can then simply paste it manually into the open file window's address bar and that way can go directly to there. A little convoluted solution and you have to take into account it overwrites anything in clipboard of course, but could save you some time and steps to get there if that's not too much a problem...
Last edited by Rai López on Sun Jan 29, 2023 9:42 pm, edited 2 times in total.
...
bbrraayyaann
Posts: 68
Joined: Thu Jan 24, 2019 3:52 am

Re: Custom path for LM.GUI.OpenFile?

Post by bbrraayyaann »

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.
User avatar
synthsin75
Posts: 10009
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Custom path for LM.GUI.OpenFile?

Post by synthsin75 »

SimplSam wrote: Sun Jan 29, 2023 3:00 pm
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.
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.
Yeah, the OP needed to open a specific directory.
You could sort the results, like when you edit for extensions, before offering them to the user.
User avatar
hayasidist
Posts: 3561
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Custom path for LM.GUI.OpenFile?

Post by hayasidist »

try this (windows):

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 
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....
bbrraayyaann
Posts: 68
Joined: Thu Jan 24, 2019 3:52 am

Re: Custom path for LM.GUI.OpenFile?

Post by bbrraayyaann »

hayasidist wrote: Mon Jan 30, 2023 10:37 am try this (windows):

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 
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....
How would it work exactly?
Does sOut return a path or string?
User avatar
hayasidist
Posts: 3561
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Custom path for LM.GUI.OpenFile?

Post by hayasidist »

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
Post Reply