Page 1 of 1

Create style trough lua script?

Posted: Thu Apr 01, 2021 1:07 pm
by Lukas
Hi everyone,

I tried to create a script to manage styles in a document, but it seems impossible... I wanted to create a script that does this:

- Loop through all shapes in all layers
- Check if layer has a 2nd assigned style
- If it doesn't, create a style based on the shapes colors (if that style doesn't already exist)
- Set that newly created style (or existing style with matching colors) as the 2nd assigned style for the shape

I intend to use the 1st assigned style for a Brush-style for the entire project, and use the 2nd style for colors only.

I've tried some stuff with moho:AddStyle(style), but the style to give as argument can not be created? I can use the style of a shape as an argument (after setting its fName property), but that gives really weird results and crashes, because the style will be linked to the shape even though that shape doesn't even have that style assigned.

Do I need to do something similar to this?

Code: Select all

local vector2 = LM.Vector2:new_local()
😑

Re: Create style trough lua script?

Posted: Thu Apr 01, 2021 1:19 pm
by Stan
Unfortunately, adding new styles through scripts is not possible yet. This subject was already discussed here: http://www.lostmarble.com/forum/viewtop ... 12&t=33235.
hayasidist wrote: Tue Dec 17, 2019 8:44 am FWIW bug reports were raised in 2014 and 2017 relevant to this subject (31984 and 39555). I've asked the (new) dev team to take a look...
Looks like we need to re-raise the bug report and ask the new "new" team to take a look... :)

Re: Create style trough lua script?

Posted: Thu Apr 01, 2021 1:41 pm
by Lukas
Stan wrote: Thu Apr 01, 2021 1:19 pm Unfortunately, adding new styles through scripts is not possible yet. This subject was already discussed here: http://www.lostmarble.com/forum/viewtop ... 12&t=33235.
hayasidist wrote: Tue Dec 17, 2019 8:44 am FWIW bug reports were raised in 2014 and 2017 relevant to this subject (31984 and 39555). I've asked the (new) dev team to take a look...
Looks like we need to re-raise the bug report and ask the new "new" team to take a look... :)
Ow... Well, at least I'm not crazy! I'll ask the new guy 😉

Re: Create style trough lua script?

Posted: Thu Apr 01, 2021 4:42 pm
by hayasidist
Stan wrote: Thu Apr 01, 2021 1:19 pm Unfortunately, adding new styles through scripts is not possible yet. This subject was already discussed here: http://www.lostmarble.com/forum/viewtop ... 12&t=33235.
hayasidist wrote: Tue Dec 17, 2019 8:44 am FWIW bug reports were raised in 2014 and 2017 relevant to this subject (31984 and 39555). I've asked the (new) dev team to take a look...
Looks like we need to re-raise the bug report and ask the new "new" team to take a look... :)
I'd been holding off re-opening some "important but not mission critical" issues until 13.5 is out the door just to help keep focus on getting Moho out of the mire of 13.0 ...

Re: Create style trough lua script?

Posted: Thu Apr 01, 2021 5:06 pm
by synthsin75
Yeah, this is a long broken bit of the API. I think I've tried to create new styles by copying an existing one, but that only seems to make a second instance instead of a copy, and if memory serves, can lead to instability in Moho.

Re: Create style trough lua script?

Posted: Thu Apr 22, 2021 2:48 pm
by Lukas
Hmm. I did manage to adjust the current style for newly drawn elements a little bit.
For example, you can adjust the color like this:

Code: Select all

local style = moho:CurrentEditStyle()
style.fLineCol:SetValue(moho.drawingLayerFrame, self.myColor)
moho:UpdateUI()
I am trying to figure out how to set the brush of the 'currentEditStyle' to a brush, with no success. Has anyone tried this and found a way?

Re: Create style trough lua script?

Posted: Thu Apr 22, 2021 4:51 pm
by synthsin75

Code: Select all

	local col = LM.rgb_color:new_local()
	col.r, col.g, col.b, col.a = 193, 43, 43, 255
	self.myColor = LM.ColorVector:new_local()
	self.myColor:Set(col)
	local style = moho:CurrentEditStyle()
	style.fLineCol:SetValue(moho.drawingLayerFrame, self.myColor)
	
	local str = LM.String:new_local()
	str:Set("Brush501.png")
	style.fBrushName = str
	moho:UpdateUI()

Re: Create style trough lua script?

Posted: Thu Apr 22, 2021 7:42 pm
by Lukas
As always, thank you Wes! I would never have thought of using "LM.String:new_local()" don't think I've seen that one before. Works great 👍

Re: Create style trough lua script?

Posted: Thu Apr 22, 2021 8:27 pm
by synthsin75
Glad I could help. :wink: