Page 1 of 1

LoadDocument returns nil and not a MohoDoc

Posted: Fri Jun 16, 2023 10:00 am
by mminsel
Hi,
I have the following issue:
When I run the following code:

Code: Select all

print(moho.document:Path())
local newDocument = moho:LoadDocument("C:/path/to/file.moho")
print(moho.document:Path())
print(tostring(newDocument))
I'll get the following printouts:

Code: Select all

""
""
nil
Moho opened the document, but the moho object is now outdoated and in addition LoadDocument is not returning anything.
Actually I wanted to open a document, do stuff, save and close it again. But this doesn't seem to be possible.

Does anyone have had this issue before? Do you have an idea on how to work around this?

Re: LoadDocument returns nil and not a MohoDoc

Posted: Fri Jun 16, 2023 10:15 am
by hayasidist
if you have a new (unnamed) document as the active tab when you run the script, you'll get the empty string back.

also load returns a document object, so you'll need print(newDocument:Path()) not print(tostring(newDocument))

Re: LoadDocument returns nil and not a MohoDoc

Posted: Fri Jun 16, 2023 11:10 am
by mminsel
hayasidist wrote: Fri Jun 16, 2023 10:15 am if you have a new (unnamed) document as the active tab when you run the script, you'll get the empty string back.

also load returns a document object, so you'll need print(newDocument:Path()) not print(tostring(newDocument))
Hi hayasidist,
Thanks for your reply. The thing is, that LoadDocument returns nil and not a new document.
Which is why print(newDocument:Path()) will raise an error. The first empty string in my example code was expected, while the second empty string looks wrong to me.

Re: LoadDocument returns nil and not a MohoDoc

Posted: Fri Jun 16, 2023 12:33 pm
by hayasidist
do you actually have a file to load at the path you gave???

take a look at (e.g.) C:\Program Files\Moho\Resources\Support\Scripts\Tool\lm_scatterbrush.lua -- with focus on function LM_ScatterBrush:LoadDocument(moho, docPath) and the places from which it's called -- the script builds a string for the path and loads existing files with no problems.

Re: LoadDocument returns nil and not a MohoDoc

Posted: Fri Jun 16, 2023 12:45 pm
by SimplSam
As already stated the only place I have seen moho:LoadDocument being used is in the Scatter Brush tool (lm_scatterbrush.lua).

I have tried the function in a bit of code, and it seems to work/load OK.

Code: Select all

local doc = moho:LoadDocument("W:/SqrCir.moho")
print(tostring(doc:Name()))
result: SqrCir