Scripted Bone Rotations Not Showing Up As Motion Or Motion Layer Key Frames


https://forum.reallusion.com/Topic459389.aspx
Print Topic | Close Window

By Lord Ashes - 5 Years Ago
As my introduction to Python scripting, I created a Python script to change the rotation of an Avatar's heard. I have the script working and when I apply it to an Avatar and play, the rotation is there. That is good.
However, the issue is that when I look at my timeline for the Avatar I don't see any key frames on the Transform layer (didn't expect any there since this is a head animation) but I also don't get any key frames on the Motion, Motion | Gesture, Motion | Motion Layer or Motion | Motion Layer | Head layer where I expected to find some keys to reflect the script added rotation.

As far as I can see, currently there is no evidence on the time line that a rotation should be applied to the head but the playback clearly shows one.

Is there something that I need to add to my script in order to update the key frames? Should my script be setting the bone rotation in a different way in order to produce key frames?

The current code that I am using is:


import RLPy
print("Get Avatar")
avatar = RLPy.RScene.GetSelectedObjects()[0]
print("Get Bones")
motion_bones = avatar.GetSkeletonComponent().GetMotionBones()
print("Get Head Bone")
bone = motion_bones[0]
for this_bone in motion_bones:
  if this_bone.GetName() == "RL_Head":
    bone = this_bone
    break
print("Create clip")
clip = avatar.GetSkeletonComponent().AddClip(RLPy.RGlobal.GetTime())
clip.SetLength(RLPy.RTime(150*1000))
print("Grab bone")
control = clip.GetControl("Layer", bone).GetDataBlock().GetControl("Rotation/RotationY")
print("Rotating...")
rotation_y = -45
frame = 0
for loop in range(16):
    print("Setting Rotation %d At Time Frame %d." %(rotation_y, frame))
    control.SetValue(RLPy.RTime(frame/60*1000, RLPy.kMilliseconds), rotation_y / 180 * RLPy.RMath.CONST_PI)
    rotation_y = rotation_y + 5
    frame = frame + 10
print("Done")
By 4u2ges - 5 Years Ago
I am not sure to call it a bug or not, but the keyframes would appear as soon as you make changes to any bone.
The easiest way, is on the first frame of the timeline select Motion Layer and click + to add a key.
By videodv - 5 Years Ago
Lord Ashes (10/3/2020)
As my introduction to Python scripting, I created a Python script to change the rotation of an Avatar's heard. I have the script working and when I apply it to an Avatar and play, the rotation is there. That is good.
However, the issue is that when I look at my timeline for the Avatar I don't see any key frames on the Transform layer (didn't expect any there since this is a head animation) but I also don't get any key frames on the Motion, Motion | Gesture, Motion | Motion Layer or Motion | Motion Layer | Head layer where I expected to find some keys to reflect the script added rotation.

As far as I can see, currently there is no evidence on the time line that a rotation should be applied to the head but the playback clearly shows one.

Is there something that I need to add to my script in order to update the key frames? Should my script be setting the bone rotation in a different way in order to produce key frames?

The current code that I am using is:


import RLPy
print("Get Avatar")
avatar = RLPy.RScene.GetSelectedObjects()[0]
print("Get Bones")
motion_bones = avatar.GetSkeletonComponent().GetMotionBones()
print("Get Head Bone")
bone = motion_bones[0]
for this_bone in motion_bones:
  if this_bone.GetName() == "RL_Head":
    bone = this_bone
    break
print("Create clip")
clip = avatar.GetSkeletonComponent().AddClip(RLPy.RGlobal.GetTime())
clip.SetLength(RLPy.RTime(150*1000))
print("Grab bone")
control = clip.GetControl("Layer", bone).GetDataBlock().GetControl("Rotation/RotationY")
print("Rotating...")
rotation_y = -45
frame = 0
for loop in range(16):
    print("Setting Rotation %d At Time Frame %d." %(rotation_y, frame))
    control.SetValue(RLPy.RTime(frame/60*1000, RLPy.kMilliseconds), rotation_y / 180 * RLPy.RMath.CONST_PI)
    rotation_y = rotation_y + 5
    frame = frame + 10
print("Done")


HI

Try putting this bit of code after the final loop and before you print "Done" and see if it helps.

#-- Update timeline --#     
RLPy.RGlobal.Stop()
RLPy.RGlobal.SetTime(RLPy.RGlobal.GetTime())

Chris


By Lord Ashes - 5 Years Ago

Try putting this bit of code after the final loop and before you print "Done" and see if it helps.
#-- Update timeline --#     
RLPy.RGlobal.Stop()
RLPy.RGlobal.SetTime(RLPy.RGlobal.GetTime())

Thanks for the suggestion but it did not help.

Here is a video of what is happening...



By 4u2ges - 5 Years Ago
HI

Try putting this bit of code after the final loop and before you print "Done" and see if it helps.

#-- Update timeline --#     
RLPy.RGlobal.Stop()
RLPy.RGlobal.SetTime(RLPy.RGlobal.GetTime())

Chris


Thanks Chris, worked for me, just had to restart iClone.
Interesting, if you run the script even once, without those 2 lines in freshly opened iClone, then adding them thereafter does not make any difference.
You have to restart iClone and run script with 2 lines added first, then it would work.
By videodv - 5 Years Ago
Lord Ashes (10/3/2020)

Try putting this bit of code after the final loop and before you print "Done" and see if it helps.
#-- Update timeline --#     
RLPy.RGlobal.Stop()
RLPy.RGlobal.SetTime(RLPy.RGlobal.GetTime())

Thanks for the suggestion but it did not help.

Here is a video of what is happening...





Hi Lord Ashes

In order to see the keys on the timeline you need to play the sequence this will update the timeline if you just scroll the timeline it will not update the keys, the script addition that I included will do this for you.

Chris.
By 4u2ges - 5 Years Ago
This whole thing with timeline update is still buggy. I know at least one way to mess it up so that nothing would work with timeline update regardless... until iClone restart.
I am sure there are more ways to screw it up, whenever I have more time I'll do a thorough testing.
By Lord Ashes - 5 Years Ago

Hi Lord Ashes
In order to see the keys on the timeline you need to play the sequence this will update the timeline if you just scroll the timeline it will not update the keys, the script addition that I included will do this for you.
Chris.


Thanks. I will give that a try.

By Lord Ashes - 5 Years Ago
I have tried both suggestions:
1. To put the stop code at the end. Restart iClone and then run script.
2. To play after running the script.
Neither solution worked for me. In both cases I still not get any key frames or motion indicating that an animation is applied.

BTW, I also discovered that the Play() function does not seem to respect the time provided. The Play() function is supposed to take a start and end time parameter but when I set it for a time interval that should be 150 frames the it plays the whole project time anyway. I am fairly sure that I am providing the correct values since I use the same values to build the animation.

By videodv - 5 Years Ago
Hi Lord Ashes

Here is the play example as I ran your original script on my system.



Chris

By Lord Ashes - 5 Years Ago
videodv (10/4/2020)
Hi Lord Ashes
Here is the play example as I ran your original script on my system.
Chris



I was not getting the same results until I checked the Bake Animation project setting. Once I did that then it generated the key frames. Are you using that option?  

By 4u2ges - 5 Years Ago
It's Caleb a problem (maybe some other too). If you try it with Caleb first after loading iClone fresh, no other avatars work after that. Need to restart iClone.

Update: Looks like ANY CC3+ character is a problem :Whistling:
By Lord Ashes - 5 Years Ago
4u2ges (10/4/2020)
It's Caleb a problem (maybe some other too). If you try it with Caleb first after loading iClone fresh, no other avatars work after that. Need to restart iClone.


I restarted iClone. Loaded Katherine. Ran script. I did not get any key frames until I switched to Bake Animation. Then, upon playing, I got the key frames. The problem I see with this is that if you have a larger scene with other stuff going on, you may not want to bake you animation yet.

By 4u2ges - 5 Years Ago
Yes, it is still a bug with CC3+ (default RL characters, converted from CC3 to CC3+ are OK). What enabling Soft Cloth Baking does is adding something to the timeline at the same time as Bones script is running.
It has the same effect as if you add any key (even transform key), after applying the bone script.

This is not the case with regular CC3 characters, which work without baking enabled as Chris has shown.
By 4u2ges - 5 Years Ago
OK got it! :)

Any character without Persona applied would not update Timeline after loading Bones script regardless.
Just remove Persona from any character and run script (with those 2 lines of code Chris suggested) - it would not update the timeline.
Add any person back to character and it would update timeline just fine.

RL CC3+ characters do not have Persona applied, that is why it was confusing.

BUG!



By videodv - 5 Years Ago

Lord Ashes (10/4/2020)
videodv (10/4/2020)
Hi Lord Ashes
Here is the play example as I ran your original script on my system.
Chris



I was not getting the same results until I checked the Bake Animation project setting. Once I did that then it generated the key frames. Are you using that option?  



Hi
No just straight default settings, i used cc3 jade in the example will test cc3+ character tomorrow

Chris

By Lord Ashes - 5 Years Ago

No just straight default settings, i used cc3 jade in the example will test cc3+ character tomorrow
Chris


Maybe that is what 4u2ges was eluding to...that it does not work with CC3+ characters. I'll have to try it with CC3 and older characters.

By AllenLee (RL) - 5 Years Ago
Hi every one,

You can try to add this.

This API can trigger other UI updates.
RLPy.RGlobal.ObjectModified(avatar, RLPy.EObjectModifiedType_Transform)

Allen Lee
By videodv - 5 Years Ago
AllenLee (RL) (10/5/2020)
Hi every one,

You can try to add this.

This API can trigger other UI updates.
RLPy.RGlobal.ObjectModified(avatar, RLPy.EObjectModifiedType_Transform)

Allen Lee



Hi Allen Lee

Just tried this and it worked fine.

Thanks
Chris.
By Lord Ashes - 5 Years Ago
Have not tried it myself yet but sounds like its a solution. Thanks Allen Lee and videodv.
By Lord Ashes - 5 Years Ago
The added code does indeed work. However, there is no explanation as to what this method call actually does (and thus why it works).

It is not documented in the RGlobal namespace (https://wiki.reallusion.com/IC_Python_API:RLPy_RGlobal).
By SeanMac - 5 Years Ago
@Ashes
Re: "We often compare ourselves to the US..."
Finding yourself reading the same joke a dozen times gets tedious.
Could you please change your joke. referably for something other than a joke?
Regards
SeanMac
By Lord Ashes - 5 Years Ago
SeanMac (10/6/2020)
@Ashes
Finding yourself reading the same joke a dozen times gets tedious.
Could you please change your joke. referably for something other than a joke?
Regards
SeanMac

How about these song lyrics...
By SeanMac - 5 Years Ago
Thanks, man.

A change is as good as a rest.
Regards

SeanMac