Changing styles and effects

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
jasonrfox
Posts: 8
Joined: Mon Mar 14, 2005 5:29 am

Changing styles and effects

Post by jasonrfox »

I am writing a script to recursively change colors throughout an existing moho document. It works great except where named styles and effects are concerned.

From other posts it appears that I can't touch the named styles at all through LUA. Is that 100% true or could I somehow access the "applied styles" list or otherwise copy a script generated style over the existing applied styles in a layer? I can definitely change the color of every shape in the document but if a named style is applied it overrides the color set by the script. Has anyone come up with a work around to modify named styles? I remember LM replying in another post that named styles are not accessible yet. How soon might that access be available? Seems like there are a number of others who would like to get at them too.

I can't find much at all on changing fill effects through scripting. I see SetSoftEdge and SetShading in M_Style but what I really want to do with the script is temporarily disable any effects that are present. Is the situation the same as with named styles in that they can't be manipulated via script?

I could even be happy if I could write out a new moho file that supresses writing of named styles and fill effects. When I reload the new file I would have all the styles and fill effects removed. That doesn't look possible either.

Does anyone have some suggestions or additional info? thanks!
User avatar
7feet
Posts: 840
Joined: Wed Aug 04, 2004 5:45 am
Location: L.I., New Yawk.
Contact:

Post by 7feet »

Well, removing style and effects from the Moho file might be a pain in the butt, but not impossible. For a hands-on kinda hack, as long as the style names don't coincide with any layer names, you could open up the Moho file in a text editor and replace, say "skin color" with "", and that style is kaput. Looking for it, it's the next to last entry of the 'shapes' section for each shape in each layer entry in the file.

If you want to get fancy, you could write something that would parse through the file to those entries and kill 'em. I'd just do it from Lua inside Moho 'cuz that's about the only thing I'm comfortable with. The shape and line effects are a little trickier as the entries vary according to the type. As an example, this is a plain old white fill/black outline box, in it's own layer:

Code: Select all

shapes 1
			"" true true true true
				4
					0 0
					0 1
					0 2
					0 3
				""
					false
					[
						keys 1
							0 0 0.1 0.5 1 1 1 1
					]
					false 0.004167
					false
					[
						keys 1
							0 0 0.1 0.5 0 0 0 1
					]
					""
					false
					6.283185
					0.25
					true
					-1
					-1
					-1
				""
				""
this one has layer (first shaded, then gradient)but no line effects, and a style:

Code: Select all

shapes 1
			"" true true true true
				4
					0 0
					0 1
					0 2
					0 3
				""
					false
					[
						keys 1
							0 0 0.1 0.5 1 1 1 1
					]
					false 0.004167
					false
					[
						keys 1
							0 0 0.1 0.5 0 0 0 1
					]
					""
					false
					6.283185
					0.25
					true
					0        -- shaded
						2.356194 0.033333 0.033333 0 0 0 128 false 
					5        -- gradient
											[
						keys 1
							0 1 0.1 0.5 4.712389
					]
							[
						keys 1
							0 1 0.1 0.5 1 1 1 1
					]
							[
						keys 1
							0 1 0.1 0.5 0 0 0 1
					]
		true 
					-1
				"tooth"  --the named style
				""
So it's not impossible, or really even that horrible if you need to do it. But I will welcome it if LM gives a touch more control over the styles. Because it's in a pretty defined spot it seems a lot easier to kill the styles. Sorry if that's not what you wanted to hear, but the best I got at the moment. I haven't really tried to mess with the styles too much as yet, as far as the scripting goes. Lemme know if you come up with something.
jasonrfox
Posts: 8
Joined: Mon Mar 14, 2005 5:29 am

Post by jasonrfox »

That's not a bad idea. I wonder if I can force moho to load the new file after it's generated by the script?

If so, then there's no reason why one couldn't write a tool that edits or creates styles in script, saves a new moho file, and invokes a load to make the change. Not very elegant but might do the trick. I haven't heard LM's stance on making styles accessible through script. My hunch is that it was simple oversight rather than intentional - the script interface has so much power. Hard to imagine LM limiting script capability on purpose.
User avatar
7feet
Posts: 840
Joined: Wed Aug 04, 2004 5:45 am
Location: L.I., New Yawk.
Contact:

Post by 7feet »

As it stands, I don't think that you can directly get Moho to reload a .moho file, but there are a number of scripts (in particular look at Janimatics batch import script {I think I did some more mod on it}) that create batch scripts to do stuff, and it would seem the most direct way at this time would be to save the reworked version of the .moho file and then use a batch script to invoke a new copy of Moho running the tweaked file. If your machine isn't a spoilsport about having a few versions of Moho running, seems like a reasonably viable way to work it for what you want to do.
Post Reply