Create style trough lua script?

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
Lukas
Posts: 1297
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Create style trough lua script?

Post 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()
😑
Stan
Posts: 199
Joined: Sun Apr 19, 2009 3:22 pm

Re: Create style trough lua script?

Post 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... :)
________________________________________________________________________
https://mohoscripting.com/ - Unofficial Moho Lua scripting documentation
https://mohoscripts.com/ - The best place to publish and download scripts for Moho
User avatar
Lukas
Posts: 1297
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Create style trough lua script?

Post 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 😉
User avatar
hayasidist
Posts: 3528
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Create style trough lua script?

Post 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 ...
User avatar
synthsin75
Posts: 9981
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Create style trough lua script?

Post 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.
User avatar
Lukas
Posts: 1297
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Create style trough lua script?

Post 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?
User avatar
synthsin75
Posts: 9981
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Create style trough lua script?

Post 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()
User avatar
Lukas
Posts: 1297
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Create style trough lua script?

Post 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 👍
User avatar
synthsin75
Posts: 9981
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Create style trough lua script?

Post by synthsin75 »

Glad I could help. :wink:
Post Reply