Undocumented LM classes

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
Stan
Posts: 199
Joined: Sun Apr 19, 2009 3:22 pm

Undocumented LM classes

Post by Stan »

A question for the Moho developer(s).

There are some undocumented classes that are used in some places but don't have any information available in the pkg files. They are: LM_Cursor, LM_Path, LM_Image.

Is there a chance we could get some information on those?

Thank you!
________________________________________________________________________
https://mohoscripting.com/ - Unofficial Moho Lua scripting documentation
https://mohoscripts.com/ - The best place to publish and download scripts for Moho
User avatar
Lost Marble
Site Admin
Posts: 2347
Joined: Tue Aug 03, 2004 6:02 pm
Location: Scotts Valley, California, USA
Contact:

Re: Undocumented LM classes

Post by Lost Marble »

Yes, I think I can do that. I'm a little swamped with other things, but here's a quick answer off the top of my head:

These are internal C++ classes that may not have been intentionally exposed to Lua.

LM_Path represents a path to a file or directory on disk. In the Lua interface, we try to expose these as plain strings, that then get translated straight into Lua strings. I think LM_Path is referenced in the Lua pkg files, but not actually fully exposed. For example, in the M_Material3D class, there's this function:

LM_Path& GetTexturePath( LM_SecureAccess **outAccess = NULL );

But I don't think you can use LM_Path from Lua. It should look more like this other function:

void SetTexturePath( const char *path, LM_SecureAccess *copyFromAccess = NULL );

There is uses a plain string that can be accessed from Lua.

LM_image is a low-level image object in the C++ code. I think the only place it gets used in the Lua code is in the LM_Button::SetImage function, which was probably not meant to be exposed to Lua. It would let you change a button's image on the fly. We can enable that abilitym but instead of a raw image object, we would probably let Lua do it by specifying the file path of the image.

Finally, LM_Cursor lets you create a mouse cursor, and you can assign it to a view (typically the canvas). You can create an LM_Cursor from a PNG image by specifying the file path to the PNG, and the coordinates of the cursor's "hot spot".
Stan
Posts: 199
Joined: Sun Apr 19, 2009 3:22 pm

Re: Undocumented LM classes

Post by Stan »

Lost Marble wrote: Sun Jan 31, 2021 8:09 pm We can enable that abilitym but instead of a raw image object, we would probably let Lua do it by specifying the file path of the image.
Yeah, that would be a really nice to have feature! Image buttons are compact and attractive, and having the ability to change their visual state on the fly would greatly increase their potential. Text buttons tend to consume too much real estate.

As for the LM_Path, as far as I remember, there was a case when one of my friends was working in a team of remote people and some of them were using PCs and others were using Macs. So there was a problem using referenced layers because the paths were different. So they tried to create a script to change the reference path and were unable to do that because the LM_Path is not exposed.

So, if possible, please consider some improvements in this area, they would be really appreciated.

Thank you Mike!
________________________________________________________________________
https://mohoscripting.com/ - Unofficial Moho Lua scripting documentation
https://mohoscripts.com/ - The best place to publish and download scripts for Moho
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: Undocumented LM classes

Post by Rai López »

Stan wrote: Sun Jan 31, 2021 8:52 pm
Lost Marble wrote: Sun Jan 31, 2021 8:09 pm ...we would probably let Lua do it by specifying the file path of the image.
Yeah, that would be a really nice to have feature! Image buttons are compact and attractive, and having the ability to change their visual state on the fly would greatly increase their potential. Text buttons tend to consume too much real estate.
@Stan: I couldn't express it better...

@Mike: PLEEEASE :mrgreen:

BTW, I ended up here because I'm trying to feed an ImageButton's path argument with a path into a Moho installation directory (concretely this one: "C:\Program Files\Moho\Resources\Images\group_type"), but all I get is a Missing resource image alert no matter what I try. I think I've tried any possible back/forward slash variations, with or without extensions, relative path from "C:\Program Files\Moho\Resources\Support\Scripts\ScriptResources" like "../../../Images/group_type", but nothing...

Do you think this is even possible? I mean, to try to access from a script (in this case a Layer Script) to this kind of resources, or for security reasons or whatever you are not allowed to reach anything outside the ScriptResources folder? And lastly, if that was the case, do you know by chance if class LM_SecureAccess could (somehow) be of any help on this? Thanks!
...
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: Undocumented LM classes

Post by Rai López »

OK, I finally got it to work! I'd have never said, but this seems to be the expected relative path construction ImageButton's path argument understand: "ScriptResources/../../Images/group_type". Cool! And good to know...
...
bbrraayyaann
Posts: 68
Joined: Thu Jan 24, 2019 3:52 am

Re: Undocumented LM classes

Post by bbrraayyaann »

Stan wrote: Sun Jan 31, 2021 5:35 pm A question for the Moho developer(s).

There are some undocumented classes that are used in some places but don't have any information available in the pkg files. They are: LM_Cursor, LM_Path, LM_Image.

Is there a chance we could get some information on those?

Thank you!
Hi, I was testing the SetImage() function.
But it doesn't work properly.
It doesn't change the image of the button, could you please explain me why?
I have tried it with the path directly "ScriptResources".
also with the full path of the .png image.
and nothing
bbrraayyaann
Posts: 68
Joined: Thu Jan 24, 2019 3:52 am

Re: Undocumented LM classes

Post by bbrraayyaann »

Ramón López wrote: Tue Oct 11, 2022 1:57 pm OK, I finally got it to work! I'd have never said, but this seems to be the expected relative path construction ImageButton's path argument understand: "ScriptResources/../../Images/group_type". Cool! And good to know...
Hi Ramon - specifically how does the SetImage() work ?
Please could you explain it to me?
User avatar
synthsin75
Posts: 9978
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Undocumented LM classes

Post by synthsin75 »

bbrraayyaann wrote: Fri Nov 11, 2022 4:50 pm
Ramón López wrote: Tue Oct 11, 2022 1:57 pm OK, I finally got it to work! I'd have never said, but this seems to be the expected relative path construction ImageButton's path argument understand: "ScriptResources/../../Images/group_type". Cool! And good to know...
Hi Ramon - specifically how does the SetImage() work ?
Please could you explain it to me?
Like Mike said above, you can't actually set LM_image, because that's a C++ object. So for scripting access, that function just doesn't work.
What you can do is use LM.GUI.ImageButton, but it's hard to change the image. You have to do something to make Moho reevaluate the tool's options (like entering/exiting frame zero, changing layers, etc., that would normally allow the script to gray-out GUI elements). See my switch icons script for an example.
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: Undocumented LM classes

Post by Rai López »

bbrraayyaann wrote: Fri Nov 11, 2022 4:50 pm
Ramón López wrote: Tue Oct 11, 2022 1:57 pmOK, I finally got it to work!
Hi Ramon - specifically how does the SetImage() work ?
Please could you explain it to me?
Hi. What I got work there was simply to can access images in the installation folders with the intention of reusing them in some of my buttons in mind, but nothing else... Unfortunately, what Wes says is right, we never got enough Lua powers to can really change image button's images on the fly as one could expect for the LM_Button:SetImage() method, and the only way nowadays would pass for resorting to workarounds, although not without limitations.

Sorry if I gave you false hope on this cause I know exactly what it feels, bro :P
...
Post Reply