Control all switch layers and bones from parent bone layer

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

Moderators: Fahim, Distinct Sun, Víctor Paredes, erey, Belgarath, slowtiger

User avatar
heyvern
Posts: 6964
Joined: Fri Sep 02, 2005 4:49 am

Control all switch layers and bones from parent bone layer

Post by heyvern » Wed Aug 08, 2012 5:27 pm

This is a layer script.

This script was used originally in the Fritz character in the Anime Studio content. I just updated this script (it's better than the one I did for the Fritz character).

Instructions and sample ASP file are included in the zip. Embed this script in a parent bone layer. Name bones in parent layer the same as sub switch layers.

hm_switch-layer-bone-control.zip



The Character Wizard content is a good example of how this can be used. Create a CW character with all views. Inside there is a TOP level switch for body angles. Nested Inside each of those layers are the same named switch folders for the mouth, eyes, hands etc etc for each view angle. Put the CW top level switch inside a new bone layer. Create and name bones for all of the nested switches, for example, Man, Mouth, Hand R, Eye R etc etc. You can now control all of those switches for all the nested levels using the top bone layer. No need to key switches by hand in each layer.

Feature overview:
Control ANY and all switch layers ANYWHERE in the document no matter how deeply nested.
Controls switching layers from parent bone layer (matching bone and layer names)
Control bone scales switch layer uniformly (x, y and z)
Control the bones in a switch using same named bones in the parent bone layer.

The "Layer Scaling" is especially fun. Anime Studio bone scaling is only on the Y axis. Bound layers can't be scaled uniformly using a single bone. This script allows for uniform scaling of the controlled switch layer by scaling the control bone. The controlled layer should NOT be bound to the control bone as this will also scale on the Y axis as well.

You can use angle limits on the control bone (bone constraints) to make the switch layer switching interval angle of the bone smaller. It just divides the number of switches into the distance between the min/max of the bone angle limits.
As an extra aid in switching, you could create a vector layer of "dials" bound to the switch control bones (see how I did this in the Fritz file in the Anime Studio content).

Let me know how this works out for you.

-vern
Last edited by heyvern on Wed Aug 08, 2012 9:23 pm, edited 1 time in total.
User avatar
heyvern
Posts: 6964
Joined: Fri Sep 02, 2005 4:49 am

Re: Control all switch layers and bones from parent bone lay

Post by heyvern » Wed Aug 08, 2012 7:58 pm

Updated the script so now you can control switch layers with the same name that don't have the same number of switch layers.

For example, one of the character wizard characters was missing a hand layer in the switch. All the the other hand switches had 2 layers. One only had 1 layer. This caused the script to not work obviously it was assumed the duplicate switches would have the same number of layers.

I tweaked the code so now it works with switches that don't have the exact same number of layers. The bone angle will adjust based on the number of layers in the switch automatically. So if you have a bunch of switches with the same name controlled by the same bone, but each one has a different number of layers, the bone angle is divided by EACH layer number.

This can however cause some situations where the layers don't "match". If that is the case you should make sure all the switches have the same number of layers.
User avatar
DK
Posts: 2425
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Re: Control all switch layers and bones from parent bone lay

Post by DK » Thu Aug 09, 2012 8:45 am

That is amazing vern!!!!!
Thanks a bunch for sharing.

Cheers
D.K
Breinmeester
Posts: 294
Joined: Thu May 13, 2010 2:01 pm

Re: Control all switch layers and bones from parent bone lay

Post by Breinmeester » Thu Aug 09, 2012 9:55 am

You're posting some valuable scripts, Vern! Glad you're back!! 8)
User avatar
hothead
Posts: 213
Joined: Mon Apr 12, 2010 10:53 pm

Re: Control all switch layers and bones from parent bone lay

Post by hothead » Fri Aug 10, 2012 1:39 am

Hey Heyvern i am soooo glay to see you back i all log in back. I am a fan of Fritz character so i am going to love this script thank you vern...
:D
User avatar
Onionskin
Posts: 223
Joined: Wed Mar 04, 2009 2:01 pm

Re: Control all switch layers and bones from parent bone lay

Post by Onionskin » Fri Aug 10, 2012 10:57 am

Awesome, switch with bone + master controle bone, it works great, thank you very much!
Now I have to find way to embed two embedded scripts on one layer, because I use very often aim_bone_ik_hl script, I should pm to Rudriger.
funksmaname
Posts: 3107
Joined: Tue May 29, 2007 11:31 am
Location: Nelson, New Zealand

Re: Control all switch layers and bones from parent bone lay

Post by funksmaname » Sun Aug 12, 2012 10:16 pm

Rudiger released a menu script to merge scripts - its around here somewhere... but essentially I think all it did was take all of one script code and put it before or after another script - you could try doing this manually to merge the two? I don't know if they can conflict but maybe worth a try :)
User avatar
heyvern
Posts: 6964
Joined: Fri Sep 02, 2005 4:49 am

Re: Control all switch layers and bones from parent bone lay

Post by heyvern » Mon Aug 13, 2012 2:50 am

My concern merging scripts is possible performance issues. With this script there is the potential for a LOT of activity going on if you have a lot of bones controlling a lot of switches and controlling bones on the switch layer. I have complex files and every once in awhile the script "chokes" for a few seconds when rotating a single bone that controls 10 to 15 switch layers simultaneously.

Another issue regarding combining scripts might be potential variable conflicts. For those who don't do any scripting, we store important stuff in little containers. You muck those up and things go wonky. when we say "variable scope" we don't mean mouth wash.

I will try to track down Rudiger's merging script. It sounds pretty cool. So does the Aim Bone script. I wrote a script like that as well. Love to see how others approach the same idea. My math skills STINK and aiming bones tends to require lots of crazy vector math. I use a lot of bookmarked math sites when writing scripts. :)

--------------

p.s. I wrote up a proposal to SM for improving layer script functionality that would solve this issue and provide the ability to put as many script features as you want into a layer using many function "snippets" in a "wrapper". I thought my concept was pretty simple and cool and might just work. It may not be any time soon, but I have my fingers crossed that it might show up in a future version of Anime Studio. We need a way to have more than one layer script. The main issue is that so many things are repeated a bazillion times over and over and over, like searching bone lists, layer lists, point lists etc. If those could be "built in" functions it could really make life easier.

-vern
rocky53204
Posts: 185
Joined: Sat Sep 03, 2011 3:34 am

Re: Control all switch layers and bones from parent bone lay

Post by rocky53204 » Thu Aug 16, 2012 6:17 pm

Once again you leave me in wide mouth astonishment! Very cool script... damn shame Smith can't use you as a developer.
guyver93
Posts: 285
Joined: Mon Sep 06, 2010 5:03 pm

Re: Control all switch layers and bones from parent bone lay

Post by guyver93 » Wed Oct 24, 2012 4:39 am

Heyvern,
Funksmaname just pointed me to this thread and all I can say is that's it feels like xmas in October! This script is amazing! I haven't used it yet but I can tell by your video that it does exactly what I need and I'm going to use it all the time! Thanks so much for this!!!!!!!!!
Practice random acts of kindness and senseless acts of beauty! Pause, consider, do! I dare you!
User avatar
DrGhaedi
Posts: 29
Joined: Sat Sep 01, 2012 6:04 pm
Location: USA

Re: Control all switch layers and bones from parent bone lay

Post by DrGhaedi » Sat Nov 03, 2012 8:24 pm

Heyvern,
Guyver93 pointed me to you and this script. Just wanted to thank you for sharing your work with the AS community.

PS
Assuming you are Jim Varney fan? Or is the Hey Vern merely a coincidence?
http://www.youtube.com/watch?v=EimYmcr18Xs :twisted:
just because nobody understands you does not make you an artist
otonal
Posts: 39
Joined: Tue Jun 05, 2012 4:44 pm

Re: Control all switch layers and bones from parent bone lay

Post by otonal » Mon Jul 08, 2013 12:17 am

i have a problem with the script as i want to cycle through Image switch layers.

when i set a bone angle at a certain keyframe i have the corresponding Image shown with your script.
when later on in timeline i change the angle, of course the corresponding Image for that is displayed.

-but for the time between those as the bones moves the Image is hold and dont directly cycle according to the moving bones angle as long as i dont keyframe them!
there is no direct link as Long as you dont keyframe the bone position sadly.


lets say i have photos of a clayhead from all angles. i would like to set a startimage/pose with your script and the endpose later in timeline. then the imagerow of the heads rotation step by step contained in the switchlayer should cycle with the altered scriptboneangle.

smart bones dont work with switch layers yet, so i hope there is a mod or a way to do it with your script. so to say to make your script animteable or maybe a second version that does that.

of course the way the script is right now is desireable in many sitauions but i could think of so many situations where a direct boneangle/ swtichlayerswitching link would be wanted as well!
User avatar
heyvern
Posts: 6964
Joined: Fri Sep 02, 2005 4:49 am

Re: Control all switch layers and bones from parent bone lay

Post by heyvern » Mon Jul 08, 2013 2:52 am

otonal wrote:i have a problem with the script as i want to cycle through Image switch layers.

when i set a bone angle at a certain keyframe i have the corresponding Image shown with your script.
when later on in timeline i change the angle, of course the corresponding Image for that is displayed.

-but for the time between those as the bones moves the Image is hold and dont directly cycle according to the moving bones angle as long as i dont keyframe them!
there is no direct link as Long as you dont keyframe the bone position sadly.
Interesting! When I made this script I actually had to avoid that effect otherwise all the layers would cycle through on every frame between keys which is not what most people want with this type of switching. So what you need is an alternative version that DOES cycle through between keys. I can probably add this functionality by checking for something added to the bone name controlling the switch layer.

Will let you know how it goes.
otonal
Posts: 39
Joined: Tue Jun 05, 2012 4:44 pm

Re: Control all switch layers and bones from parent bone lay

Post by otonal » Mon Jul 08, 2013 10:16 am

8)
RichardU
Posts: 155
Joined: Sun Mar 20, 2011 6:53 pm
Location: Atlanta

Re: Control all switch layers and bones from parent bone lay

Post by RichardU » Thu Jul 11, 2013 4:11 pm

This is way cool, but there is one final thing I can't seem to control from the highest bone layer. I have a sub bone layer for Head, with Smartbones to control vector layers inside. I'm trying to figure out how to have those smartbones on the highest bone layer. I've tried converting the Head bone layer to a group layer, but I can't get the highest bone layer to do point animation on vector layers within a sub group/bone layer. What's the best workaround?
Post Reply