Difference between revisions of "IC Python API:iClone Events System"

From Reallusion Wiki!
Jump to: navigation, search
(Created page with "iClone Events are a way of allowing user driven callback to persist from edit time to run time without the need for additional programming and script configuration. iClone Eve...")
 
m (Example Code)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
{{TOC}}
 +
{{Parent|IC_Python_API|iClone Python API}}
 +
 
iClone Events are a way of allowing user driven callback to persist from edit time to run time without the need for additional programming and script configuration. iClone Events are useful for a number of things:
 
iClone Events are a way of allowing user driven callback to persist from edit time to run time without the need for additional programming and script configuration. iClone Events are useful for a number of things:
  
#Content driven callbacks   
+
*Content driven callbacks   
#Persistent callbacks
+
*Persistent callbacks
#Preconfigured call events
+
*Preconfigured call events
  
 
== Using iClone Events ==
 
== Using iClone Events ==
Line 17: Line 20:
 
== iClone Events List ==
 
== iClone Events List ==
  
There are several Events that iClone provided, listed below:
+
iClone provides several events:
  
===System Event===
+
===System Events===
  
 
You can configure callback functions for the following event triggers:
 
You can configure callback functions for the following event triggers:
Line 32: Line 35:
 
*Changing the the timeline by shortening or elongating its duration.
 
*Changing the the timeline by shortening or elongating its duration.
  
===Dialogue Event===
+
===Dialogue Events===
  
 
If you using RIDialog or RIDockWidget to create your UI, you could receive the events below:
 
If you using RIDialog or RIDockWidget to create your UI, you could receive the events below:
Line 40: Line 43:
 
*Close
 
*Close
  
===Timer Event===
+
===Timer Events===
  
Using the RLPyTimer will receive the events below:
+
RLPyTimer can receive the events below:
  
 
*Time Out
 
*Time Out
Line 50: Line 53:
 
The following code demonstrates the use of RPyTimer event to execute an update function every 100 ms.
 
The following code demonstrates the use of RPyTimer event to execute an update function every 100 ms.
  
{{code|<nowiki>
+
<syntaxhighlight lang="Python">
 
import RLPy
 
import RLPy
 
import time
 
import time
Line 99: Line 102:
 
     #-- Start Timer --#
 
     #-- Start Timer --#
 
     timer_event.Start()
 
     timer_event.Start()
</nowiki>}}
+
</syntaxhighlight>

Latest revision as of 01:18, 9 April 2019

Main article: iClone Python API.

iClone Events are a way of allowing user driven callback to persist from edit time to run time without the need for additional programming and script configuration. iClone Events are useful for a number of things:

  • Content driven callbacks
  • Persistent callbacks
  • Preconfigured call events

Using iClone Events

To configure a callback in the editor there are a few steps to take:

  1. Make sure your script imports and uses RLPy or related class.
  2. Set global variable(s) for event and event callback.
  3. Register the event and set its corresponding callback
  4. Overwrite the event callback to the received event
  5. Select the function you wish to be called

iClone Events List

iClone provides several events:

System Events

You can configure callback functions for the following event triggers:

  • Adding objects to the scene.
  • Removing objects from the scene.
  • Changing the current seletion.
  • Deselecting an object.
  • Performing undos and redos.
  • Playing or stopping the timeline playback.
  • Changing the current timeframe, i.e. dragging the playhead in the timeline.
  • Changing the the timeline by shortening or elongating its duration.

Dialogue Events

If you using RIDialog or RIDockWidget to create your UI, you could receive the events below:

  • Show
  • Hide
  • Close

Timer Events

RLPyTimer can receive the events below:

  • Time Out

Example Code

The following code demonstrates the use of RPyTimer event to execute an update function every 100 ms.

import RLPy
import time

#-- Initialize the global variable --#
timer_event = None
timer_event_callback = None

#Make a count
count = 0

#-- Overriding RL Timer class --#
class RLPyTimerCallback(RLPy.RPyTimerCallback):
    def __init__(self):
        RLPy.RPyTimerCallback.__init__(self)
	
    #-- Overriding Timeout --#
    def Timeout(self):
        global count
        global timer_event
        global timer_event_callback
        #-- When count more than 10, then Stop the Timer event --#
        if (count < 10):
            count +=1
            #-- Print current in the Console Log panel --#
            print (time.time())
        else:
            #-- Stop the Timer event --#
            timer_event.Stop()
            #-- Unregister Timer Event to save the resource --#
            timer_event.UnregisterPyTimerCallback(timer_event_callback) 


def run_script():
    global timer_event
    global timer_event_callback
	
    #-- Initialize the Timer --#
    timer_event = RLPy.RPyTimer()
    timer_event.SetInterval(100)
	
    #-- Initialize the Timer Callback --#
    timer_event_callback = RLPyTimerCallback()
	
    #-- Register Timer Event to Timer Callback --#
    timer_event.RegisterPyTimerCallback(timer_event_callback) 
    
    #-- Start Timer --#
    timer_event.Start()