Question about Embedded Scripts and Dialog Window...

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
Rai López
Posts: 2242
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Question about Embedded Scripts and Dialog Window...

Post by Rai López »

Can Embedded Scripts open a dialog window like any other script to set adjustments or imput parameters when it is loaded? Can you answer as if yes as if is not? [...] And, if finally is yes :D, somebody can post any example or clue? Any experiment?? Well, that's all, THANK YOU!!!
User avatar
Lost Marble
Site Admin
Posts: 2347
Joined: Tue Aug 03, 2004 6:02 pm
Location: Scotts Valley, California, USA
Contact:

Post by Lost Marble »

I think that would be possible, but there are a couple details you would need to figure out:

1. After entering the details, the script would need to save them somehow. An embedded script cannot just save whatever data it wants into a Moho file (although that might be a good future feature). The script would need to save an extra data file along with the Moho file if it had some data that needed to be recovered the next time you open the file.

2. When you re-open the Moho file, you probably wouldn't want the script to bring up the dialog again. The way to prevent this would be for the script to first check for the data file it previously saved - if the file exists, just read the data. If not, then it might have to bring up the dialog again.

I'll try writing an embedded script like this later today.
User avatar
Rai López
Posts: 2242
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

...THANK YOU LM!!! :D That can be a very POWERFULL solution/posibility for some situations, and can open a whole new world of posibilities! I think that you did a GREAT effort to add this incredible feature for us and all this work only can bring us lots of joy :D , if not yet, sure that in the near future at least :roll: ...I only can be sorry cause my very :oops: POOR :oops: knowledges about scripting :cry: ...but THANK YOU (again) to help too in this issue :) *CIAO!*
User avatar
Lost Marble
Site Admin
Posts: 2347
Joined: Tue Aug 03, 2004 6:02 pm
Location: Scotts Valley, California, USA
Contact:

Post by Lost Marble »

*** UPDATE 9/18/2012 ***
Please note that this thread is very old (7 years old - wow!).
The example I originally posted here is no longer quite correct.
Please see my new posting later in the thread for the right way to do this in version 9 of Anime Studio.
*** UPDATE 9/18/2012 ***

OK, I've worked up a simple example of this:

http://www.lostmarble.com/misc/embedded_ui.zip

To try it out, open the file hanging_sample.moho. Play the animation to see what it does right now. (This is basically the same as the original embedded script sample.)

Next, double-click the "Layer 2" layer to bring up the Layer Settings dialog. Turn on the "Embedded script file" checkbox, and when prompted, select the hanging_bone.lua file. When you click OK in Layer Settings, a new dialog will come up - this dialog is being run by the embedded script you just attached to the layer.

It's not a very complex dialog, it just tests the idea. In the original embedded script example, the hanging bone just hangs downward. This script allows you to choose the angle it will hang at - try something other than straight down.

A couple things about using dialogs in embedded scripts:

1. Be careful to only invoke the dialog once. Notice that this script checks to see if the dialog is done - otherwise you would end up with the dialog coming up over and over again.

2. The Cancel button doesn't really work as expected - the script will still be embedded. Cancel just ignores any settings you enter. The problem is that an embedded script does not have the ability to remove itself.

3. If you want to change the settings in the dialog, you need to remove the embedded script, and re-attach it to the layer.

4. If you save the Moho file and re-open it, the dialog will appear again. The script does not save its settings. It could be modified to save a data file when the user clicks OK, and to restore that data file if it exists instead of re-invoking the dialog when the file is opened. The problem is if you use the script on multiple layers - it would then need to be able to save either separate data files, or all the data in one file without mixing things up. It could get kind of complicated to manage.
User avatar
Rai López
Posts: 2242
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

:arrow: THANKS! You've been very kind doing and posting that example! :D ...I've been tested and "study" it and I think that it is a good begining to understand how embedded scripts works and how much possiblities we can achieve with it, I hope that in the future somebody reach the control of all this to develop all that things that you say that can be achieved, like that external data file for settings, as USEFULL as complicated to do yes, I can understand it... Well, I'll go on with my first steps (in this issue I always am in the first steps :roll: ) ...THANK YOU for your work & time! *CIAO*

EDIT: I've observed that if you animate any channel of the scripted bone and you undo... the dialog pop up window returns :!: , it seems to me like a curious thing...
Last edited by Rai López on Fri Mar 24, 2006 5:31 pm, edited 1 time in total.
User avatar
bupaje
Posts: 1175
Joined: Fri Nov 12, 2004 5:44 pm
Location: California
Contact:

Post by bupaje »

@LM - This may be a dumb suggestion as I have forgotten what little I knew about programming but .... I remember way back some VB controls had an ItemData property and sometimes people would store small amounts of data with it. Would it be possible to add to Moho layers a similar property designed to hold a very small amount of data?

The script writers might find it useful to store small amount of text or numeric data this way. Maybe something as simple as "If Layer1.ItemData = 1 Then ShowDialogue Else DontShowIt

Alternately maybe the Note Layer can somehow be used to store a small amount of data? Say naming a note layer the same as your other layer "If Exists NoteLayer.Name = Vector.{LayerName} Then VectorVariable = NoteVariable or to store the settings i.e. 22,11,0.15, etc


If this makes no sense then it was somebody else using my account to write this. ;)
[url=http://burtabreu.animationblogspot.com:2gityfdw]My AnimationBlogSpot[/url:2gityfdw]
User avatar
Lost Marble
Site Admin
Posts: 2347
Joined: Tue Aug 03, 2004 6:02 pm
Location: Scotts Valley, California, USA
Contact:

Post by Lost Marble »

Yes, that would be a logical next step - for embedded scripts to be able to store some data in the Moho file itself. It isn't possible right now, but would be a logical future feature.
User avatar
Rai López
Posts: 2242
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

...EY! :D And... what about something like an "empty/generic" Embedded Tool that you select to can invoque a main window sensitive dialog with specifical embedded script settings of the current layer? I think this option could be even more interesting that dialogue window way, cause you'd have acces to the embedded script settings when you want and with more flexibility/integration, and well, I wonder if something like this could be possible rigth now... hmmm... I'm thinking in a lot of possibilities... :)
User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Post by Fazek »

I have an idea, but I am not sure it is working anyway. You can create a sub-layer inside the group layer (switch the Visible option off) and keep the values you need in this special layer as bone positions, rotations or as point coordinates in a mesh.

This is an ugly solution, but you can handle any number of animated parameters for your layer script this way. Maybe a standard way to handle this, with a tool button and with a function library to build such scripts easier, would be interesting...
- - - Fazek
User avatar
Rai López
Posts: 2242
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

EY! :D THANK YOU for all your help Fazek! And althought you don't believe it I tried something like that in the past with the idea of can get animatable Particle Parameters along the time (that ancient wish :roll:) based on certain bones rotation/scaling factors according with the parameter... but, of course, finally it resulted too much long and complicated and I abandoned it :(, but although a little ugly, yes... I still think that could be like a good idea or even the one solution to can achive that pourpose actually... in the other hand, I entrust too that Particle Settings be animatable in a near version of the program :) ...Well, and now I must go to thank you for another favour in the Scripting section, you know, that MARVELOUS lines of code to know the "real" bones position that I discovered yesterday, uf... you don't know how much I LOVE it guy! :D ...SEE YOU THERE!
User avatar
Lost Marble
Site Admin
Posts: 2347
Joined: Tue Aug 03, 2004 6:02 pm
Location: Scotts Valley, California, USA
Contact:

Re: Question about Embedded Scripts and Dialog Window...

Post by Lost Marble »

*** New And Improved 9/18/2012

It was pointed out to me that there were some problems with my example. Well, that example was 7 years old and I guess some things have changed (It was created with Moho version 5.2, and we're now on Anime Studio 9). I've updated the example file so that it works correctly with the current version of Anime Studio. Here's where to download the new and improved version:

http://www.lostmarble.com/misc/embedded_ui_AS9.zip

I've made three changes:

* First, it's still important to not invoke the dialog multiple times. The logic for preventing that was flawed in the original script - I've fixed that.

* Second, the original script wasn't really complete - it was just a rough proof of concept. I made some comments about saving script information in a data file, but left that up to you to figure out. Since the time I wrote that example, I've added metadata to Anime Studio layers. This means a script can store arbitrary data inside a layer, that data gets saved with the project file, and it can be re-loaded again for the script to use in the future. No need to manage your own data files. The example has been updated to show how to do this - search for "Metadata" in the Lua file.

* Finally, the script didn't gracefully handle the case where the user added the script, then later removed it, and finally re-added it and wanted to change the settings in the dialog. This updated script now handles this with the "NewLayerScript" metadata parameter. This is a boolean value that gets reset to true whenever the user changes the embedded layer script - by inspecting this value, your script can test whether it should think of itself as a "fresh copy", or whether it has been run before.

Caveat: The "NewLayerScript" parameter is a new feature coming in Anime 9.1. In 9.0 and earlier it doesn't exist. Everything else in this updated example should work fine in Anime 9.0.
User avatar
synthsin75
Posts: 9969
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Question about Embedded Scripts and Dialog Window...

Post by synthsin75 »

Thanks, Mike.
Post Reply