import math, RLPy
import os
import winreg
import PySide2
from PySide2 import *
from PySide2.shiboken2 import wrapInstance
play_length = 30000
#play_length = 5000
def initialize_plugin():
# Add menu
ic_dlg = wrapInstance(int(RLPy.RUi.GetMainWindow()), QtWidgets.QMainWindow)
plugin_menu = ic_dlg.menuBar().findChild(QtWidgets.QMenu, "pysample_menu")
if (plugin_menu == None):
plugin_menu = wrapInstance(int(RLPy.RUi.AddMenu("Python Samples", RLPy.EMenu_Plugins)), QtWidgets.QMenu)
plugin_menu.setObjectName("pysample_menu")
hello_world_action = plugin_menu.addAction("Hello World")
hello_world_action.triggered.connect(do_work)
def do_work():
#-- Get Characters from current scene --#
avatar_list = RLPy.RScene.GetAvatars()
#-- Get First Character --#
avatar = avatar_list[0]
# Clear all annimations
RLPy.RGlobal.RemoveAllAnimations( avatar 
#-- Get Skin Bone Data --#
skin_bone = avatar.GetSkeletonComponent().GetSkinBones()
#-- Get Motion Bone Data --#
motion_bone = avatar.GetSkeletonComponent().GetMotionBones()
#-- Get First Clip --#
animation_clip = avatar.GetSkeletonComponent().GetClip(0)
#-- Extend the Clip length --#
animation_clip.SetLength(RLPy.RTime(play_length))
do_work1(animation_clip, motion_bone)
load_motionplus(avatar)
RLPy.RGlobal.Play(RLPy.RTime(0), RLPy.RTime(play_length))
def do_work1(animation_clip, motion_bone):
#-- Find head bone --#
for bone in motion_bone:
if bone.GetName() == "RL_Head":
print("found head")
#-- Get Key from Layer --#
head_control = animation_clip.GetControl("Layer", bone)
data_block = head_control.GetDataBlock()
float_control_rotate_x = data_block.GetControl("Rotation/RotationX")
#-- Set Key in current time to rotate the head bone to 90 degree --#
float_control_rotate_x.SetValue(RLPy.RTime(0), math.radians(0))
float_control_rotate_x.SetValue(RLPy.RTime(500), math.radians(90))
print("done")
def load_motionplus(avatar):
# Get the iClone 7 default template path
registry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
rawKey = winreg.OpenKey(registry, r"SOFTWARE\Reallusion\iClone\7.0")
ic_template_path = os.path.abspath(
winreg.QueryValueEx(rawKey, "Template Data")[0])
RLPy.RGlobal.SetTime(RLPy.RTime(1000))
# Load Box_001.iProp
RLPy.RFileIO.LoadFile(
ic_template_path + "//iClone Template//MotionPlus//Female//Heidi_Talk 1.iMotionplus")
RLPy.RGlobal.SetTime(RLPy.RTime(25500))
RLPy.RFileIO.LoadFile(
ic_template_path + "//iClone Template//MotionPlus//Female//Heidi_Talk 2.iMotionplus")
do_work()