make layer unselectable?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

make layer unselectable?

Post by davoodice2 »

can be done though script?
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
User avatar
hayasidist
Posts: 3526
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: make layer unselectable?

Post by hayasidist »

you can lock a layer via scripting: https://mohoscripting.com/methods/576 but it can still be selected
User avatar
synthsin75
Posts: 9979
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: make layer unselectable?

Post by synthsin75 »

From my lock layer script:

Code: Select all

function Syn_LockLayer:IsRelevant(moho)
	--keep locked layer from being selected
	if (moho.frame > 0) and (moho.layer:IsLocked()) and (self.lastLayer) and (moho.document:IsLayerValid(self.lastLayer)) then
		moho:SetSelLayer(self.lastLayer)
	end
	self.lastLayer = moho.layer
end
On frames > 0, selecting a locked layer instantly selects the last selected layer. For the user, it just looks like they can't select that layer.


EDIT: Forgot to include the assignment of self.lastLayer
Last edited by synthsin75 on Fri Sep 03, 2021 12:56 am, edited 2 times in total.
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: make layer unselectable?

Post by Greenlaw »

Oh, that's clever! :D
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

Re: make layer unselectable?

Post by davoodice2 »

synthsin75 wrote: Thu Sep 02, 2021 5:23 pm From my lock layer script:

Code: Select all

function Syn_LockLayer:IsRelevant(moho)
	--keep locked layer from being selected
	if (moho.frame > 0) and (moho.layer:IsLocked()) and (self.lastLayer) and (moho.document:IsLayerValid(self.lastLayer)) then
		moho:SetSelLayer(self.lastLayer)
	end
	self.lastLayer = moho.layer
end
On frames > 0, selecting a locked layer instantly selects the last selected layer. For the user, it just looks like they can't select that layer.


EDIT: Forgot to include the assignment of self.lastLayer
very interested! . now is it possible to change it to ignore locked layer and select behind layer?
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
User avatar
synthsin75
Posts: 9979
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: make layer unselectable?

Post by synthsin75 »

davoodice2 wrote: Fri Sep 03, 2021 8:03 am very interested! . now is it possible to change it to ignore locked layer and select behind layer?
I don't understand.

How do you want to define an unselectable layer?
And do you want it to select the next layer down when it finds one?
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

Re: make layer unselectable?

Post by davoodice2 »

synthsin75 wrote: Fri Sep 03, 2021 5:52 pm
davoodice2 wrote: Fri Sep 03, 2021 8:03 am very interested! . now is it possible to change it to ignore locked layer and select behind layer?
And do you want it to select the next layer down when it finds one?
exactly!
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
User avatar
synthsin75
Posts: 9979
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: make layer unselectable?

Post by synthsin75 »

davoodice2 wrote: Fri Sep 03, 2021 11:02 pm
synthsin75 wrote: Fri Sep 03, 2021 5:52 pm And do you want it to select the next layer down when it finds one?
exactly!
If you want to go to the next layer down, including to the next group, you'll have to create a table of all the layers in the document, in layer window order.

I have a routine for that, called Recursive, in the Utility functions sections of my switch icons tool. You'll just have to find the clicked layer on that table of layers and select the next layer in the table.
Post Reply