LK_LayerFinder

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

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: LK_LayerFinder

Post by Rai López »

BigBoiiiJones wrote: Fri Sep 15, 2023 10:11 pm Just curious though you think it's possible to do something like this but for shapes in a layer? With the new liquid shapes it could be messy trying to figure out what order all the shapes are in so having a layer like panel display all of them and even rename name them and reorder them through dragging would be amazing.
Well, I finally decided to start the transitioning from what I had to a floating modeless dialog. It just seemed the perfect opportunity to start dealing with all this and, of course, with Lukas having paved all the way, the decision was much easier (thanks so much again :)). Plus, try to improve Liquid Shapes (ahem, best feature ever) management is really worth the effort, and the new possibilities regarding dialogs in M14 are simply too exiting! There are still some limitations to deal with, like not being able to save & load dialogs position, but let's see how far I can go with all this from now on for my own... Cheers!
...
User avatar
Lukas
Posts: 1297
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: LK_LayerFinder

Post by Lukas »

You give me too much credit Rai López! A textlist simply didn't cross my mind, I kind of forgot that it existed haha. Now I'm wondering if it would be better, as it can display selection with a color, instead of adding symbol to the button text... I did try to use a scrollbar, but couldn't get it to work, and kind of assumed it was impossible due to an incomplete API. And the code is far from optimized, it definitely updates the whole thing each time, and not in a very efficient way, it loops through all layers a bunch of time I'm afraid. But this was quick to create this way, and I'd rather not invest too much time in a system that might be unstable. I will definitely optimize it at some point, if modeless windows turn out to be trustworthy. But at least, I'm happy to contribute to the scripting community either way!

I'm going to check out your shape script, I'm very curious!

But please be aware of this issue SimplSam mentioned in Discord:
SimpSam wrote: So far an issue I see is the modeless panels' Event Messages get detached, and the UI effectively fails to respond to its dialog user events & changes. This is not specific to this tool and has been discussed in the forums - where it seems that the modeless message handler (LM_SimpleDialog:HandleMessage) doesn't get fired, but instead the events gets sent to a SimpleDialog Message Handler in the main modal active Tool - if it has one. Following this 'detached event' state, closing and reopening the modeless dialog can lead to a crash.
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: LK_LayerFinder

Post by Rai López »

Lukas wrote: Tue Sep 19, 2023 9:09 am You give me too much credit Rai López! A textlist simply didn't cross my mind, I kind of forgot that it existed haha. Now I'm wondering if it would be better, as it can display selection with a color, instead of adding symbol to the button text...
I don't think so! But if there were no powerful/performance reasons for avoiding them, you should definitely give them a whirl, they are indeed perfect to simulate Layers palette functionality (except drag & drop, of course, I whish!) and, although there are some other limitations and peculiarities in the way they work there are a lot of things that can be accomplished in a much convenient way than using any other widget.

Lukas wrote: Tue Sep 19, 2023 9:09 am I did try to use a scrollbar, but couldn't get it to work, and kind of assumed it was impossible due to an incomplete API. And the code is far from optimized, it definitely updates the whole thing each time, and not in a very efficient way, it loops through all layers a bunch of time I'm afraid. But this was quick to create this way [...]
Yeah! The old Scrollbar widget issue... It's a pity it never got to really work cause it could be incredible useful precisely for taking the most of this kind of dialogs in the absence of being able to perform some kind of layout redraw, but well... So we are more or less in the same situation regarding code optimization, in both cases it had to be done quickly but once it "works" it's hard to go back 😅. And I'm still trying to figure out a lot of things regarding the logic of events in this kind of new area (some things work, most things not), so I'm afraid that part will have to wait.

Lukas wrote: Tue Sep 19, 2023 9:09 am But at least, I'm happy to contribute to the scripting community either way!
You definitely does 😌

Lukas wrote: Tue Sep 19, 2023 9:09 am But please be aware of this issue SimplSam mentioned in Discord:
SimpSam wrote: So far an issue I see is the modeless panels' Event Messages get detached, and the UI effectively fails to respond to its dialog user events & changes. This is not specific to this tool and has been discussed in the forums - where it seems that the modeless message handler (LM_SimpleDialog:HandleMessage) doesn't get fired, but instead the events gets sent to a SimpleDialog Message Handler in the main modal active Tool - if it has one. Following this 'detached event' state, closing and reopening the modeless dialog can lead to a crash.
Hmm, I think it rings a bell? Maybe I read the forum discussion but may have to get back to it again since it does sound worrying... not so much the part about losing the "connection", which I guess at least could be restored by reopening the dialog, but very specially if it ends up leading to a crash. I don't think I've experienced such behavior yet (provably cause I didn't have active a tool with a dialog), but coming the info from SimplSam, I'm afraid it's only a matter of time... Oh, well, we'll see... at the moment, I'm still in the happy hours of constructing the UI, so: :)
...
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: LK_LayerFinder

Post by Greenlaw »

Lukas, I finally got around to trying your new Layer Finder tool, and I'm happy to report that it does exactly what I need.

I wanted a direct way to select a nested Switch layer to load it into the Switch Selection window, but this has always been a problem because I routinely use Group layers inside a Switch layer so each drawing can have multiple layers and use masks. This means when I use Shift+Alt+Right Click on the workspace artwork, it always selects the artwork's immediate parent Group layer, not the Switch layer.

But when I add the 'Rig' tag to the Switch layer, it shows up as a clickable button in Layer Finder's Rig Mode. That's so awesome! It's a different approach, but the result is what I was looking for.

Another problem it solves is that I can import my master rig project files into my scene project files, and retain the ability to select the nested Switch layers with Layer Finder because the 'Rig' tag stays with the rig. Double-awesome!

Thanks for coming up with a simple but great solution to a problem I've wanted to solve for a long time! :D
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: LK_LayerFinder

Post by Greenlaw »

Hmm...Layer Finder worked fine earlier today, but when I started using Layer Finder to list multiple Switch layers, something broke. Even though I have two switch layers listed in Layer Finder, I can only select one of them.

To start over, I tried removing the tags from the Switch layers, but I found that I could not remove the tags. I can delete the tags in Layer Properties, but they reappear after I click Apply in the Layer Properties window. Weird.

I'm going to start over from scratch and see if this happens again, and wll let you know how it goes.
Last edited by Greenlaw on Sun Sep 24, 2023 11:59 pm, edited 1 time in total.
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: LK_LayerFinder

Post by Greenlaw »

Could it be because this rig had been imported to another project (a new clean project,) and the first 'Rig' tag had been added to the first Switch layer in the original project file, and the second 'Rig' tag to the second Switch layer after importing the rig?

I'm not using Import As Reference for this test, so that's not a factor.

I'll test this for a little longer today and post what I find.
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: LK_LayerFinder

Post by Greenlaw »

Huh...mysteriously, it's working again. I don't know what I did to make it work.

I still have a question about removing a layer from Layer Finder. I can't seem to remove it by deleting the 'Rig' tag. Any suggestions?
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: LK_LayerFinder

Post by Greenlaw »

I neglected to mention one thing: Moho had crashed efore my last test (previous post,) so when I relaunched, a recovered version of the project was opened. This was the version that is working correctly now.

So, I'm guessing something funny was going on with Moho, and not Layer Finder. TBD.

I'm still wondering how to remove a 'Rig' layer from Layer Finder though. Thanks in advance for any tips! :D
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: LK_LayerFinder

Post by Greenlaw »

I figured it out. For anyone who needs to know...

1. Right Click over the layer and select Remove Tags. A small window will open,
2. Enter the name of the tag you wish to remove.
3. Click Remove. The tag should be gone.

Unfortunately, Moho does not list the currently embedded tags, so you need to type the name of the tag you want to remove exactly as it was written. In my case, the tag to remove was called 'Switch Rig'. It would be much easier if I could just select one or more existing tags from a list and click Remove.
Last edited by Greenlaw on Mon Sep 25, 2023 12:25 am, edited 3 times in total.
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: LK_LayerFinder

Post by Greenlaw »

@Lost Marble, I'd like to see the process of removing a tag become a little more streamlined and intuitive as described in the above post.

In general, I'd like to see Moho's tags system get a little love in a future release. The ability to tag layers has much potential, but Moho's tags UI hasn't been improved since this feature was introduced.

Thanks for listening, guys! :D
User avatar
Lukas
Posts: 1297
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: LK_LayerFinder

Post by Lukas »

Happy to hear it's useful to you Greenlaw! :)

So the issue was the tags, not the script, right? And has the panel ever become unresponsive? Or has it been stable all this time?

...In your case, the tag 'rig' does not make much sense right? Maybe it should be 'fav' or 'anim'? What do you reckon?

Be aware that selecting a 'rig'-tagged-layer with the tool also selects keyed children (if the tagged layer is a group/bone/switch layer, not if its a vector etc, of course).

Here's an old script I've never published (I think?) that I use to quickly add/remove certain tags that we use in our pipeline: https://mohoscripts.com/script/LK_Tagger It's a bit bloated, and I will update it at some point to be more specific. But it's probably useful in your situation and it's easy to use.
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: LK_LayerFinder

Post by Greenlaw »

Thanks, Lukas!

I need to work with LK_LayerFinder a bit more to give sensible answers to your questions, but it seemed to be working well where I left off the other day. Will post more feedback later.

I'll play around with LK_Tagger tonight. :D
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: LK_LayerFinder

Post by Rai López »

Lukas wrote: Tue Sep 19, 2023 9:09 am But please be aware of this issue SimplSam mentioned in Discord:
SimpSam wrote: So far an issue I see is the modeless panels' Event Messages get detached, and the UI effectively fails to respond to its dialog user events & changes. This is not specific to this tool and has been discussed in the forums - where it seems that the modeless message handler (LM_SimpleDialog:HandleMessage) doesn't get fired, but instead the events gets sent to a SimpleDialog Message Handler in the main modal active Tool - if it has one. Following this 'detached event' state, closing and reopening the modeless dialog can lead to a crash.
Hi. It's been a while cause all this is taking to me much more time than the expected (what a :o) but at least, and FWIW in the meantime, I think I found a possible "workaround" for that to happen, which has been a great relieve... For me, it has being as simple as add a line for creating a dumb dialog instance just between creating the actual instance and the DoModeless() call for, somehow, cheat Moho. E.g., like this...

Code: Select all

function RL_ShapesWindow:Run(moho)
	if self.dlog == nil then
		self.dlog = RL_ShapesWindowDialog:new(moho)
		self.dlogBypass = RL_ShapesWindowDialog:new(moho) self.dlogBypass = nil --dlogGuard, dlogShield, dlogBait, dlogTrap, dlogPatch...
		self.dlog:DoModeless()
	else
		LM.Beep()
	end
end
...and that way avoid internal dialogs management to get messed up (for some reason) by it. Otherwise, as you know it ended up creating the problems and crashes we have been talking about, for which I firstly had to find a way to prevent the dialog window could be opened if the current tool's toolbar had a dialog on it, but of course that simply was a too inconvenient/desperate patch... The key to get to this, was that at some point even the Lua Console Window's cancel message started to interfere with my modeless dialog if it jumped in the right time just before creating its instance, and that definitely gave me a clue.

Well, I hope it also works for you and help (till officially fixed at least) anyone trying to take the most of these super exciting new way of tools creation!
...
User avatar
synthsin75
Posts: 9977
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: LK_LayerFinder

Post by synthsin75 »

Thanks, Rai!

When/if I ever find time to script more, I'm sure this will come in handy.
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: LK_LayerFinder

Post by Rai López »

You're welcome, Wes! For you (when/if the time allow, of course) and those interested, the EXACT steps (assuming Lukas' script is installed) to reproduce the crash under this kind of modeless window scenario is as follows:
  1. In a fresh Moho instance, create a new document and add a Bone layer to it (this is only to ensure you can select a Select Bone tool in the next step).
  2. Well, now with the just created Bone layer active, simply select the Select Bone tool (it could be any tool with a dialog) if it's not been auto-selected yet.
  3. Open the LayerFinder window and press e.g. its arrow buttons just to see they respond and change as expected.
  4. Now, select any other tool like e.g. Transform Layer, and check that the window's controls/buttons still respond as expected (they should).
  5. BUT, again, select the Select Bone tool again and test the buttons one more time; they have stopped to respond...
  6. Well, close the dialog window, select any other tool and Moho will crash.
These order of events, along with the Lua Console clue, were very important to get what & when could be going on, so there they are for the record (now that I still could hardly remember them) just in case they also help for a fix. Well, up to this point, now one could simply add the one-line workaround in this case at the bottom of the script (which is the typical use case anyway) as follows:

Code: Select all

-- **************************************************
-- The guts of this script
-- **************************************************

function LK_LayerFinder:Run(moho)
	if self.dialog == nil then
		self.dialog = LK_LayerFinderDialog:new(moho)
		self.dlogBypass = LK_LayerFinderDialog:new(moho) self.dlogBypass = nil --JUST COMMENT AND UNCOMMENT THIS ONLY LINE AND RELAUNCH/RELOAD TO CHECK THE DIFFERENCE!
		self.dialog:DoModeless()
	end
end
And the unresponsive controls plus the systematically subsequent crash should stop happening, or at least that's what I've been getting in the last few days of thoroughly testing it. But of course the more people can confirm under different use cases the better because with workarounds you never know...

In any case! All this modeless thing is so exciting... Wes, you are one of the big ones and I'm sure you enjoy doing it (well, I guess most of the time as all of us :roll:), so I hope you can find such time for scripting again at any appropriated point for you, for yours and everyone's benefit. Cheers!
...
Post Reply