Difference between revisions of "IC Python API:iClone Events System"
From Reallusion Wiki!
Chuck (RL) (Talk | contribs) m |
Chuck (RL) (Talk | contribs) m (→Example Code) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
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 | |
− | + | *Persistent callbacks | |
− | + | *Preconfigured call events | |
== Using iClone Events == | == Using iClone Events == | ||
Line 20: | Line 20: | ||
== iClone Events List == | == iClone Events List == | ||
− | + | iClone provides several events: | |
− | ===System | + | ===System Events=== |
You can configure callback functions for the following event triggers: | You can configure callback functions for the following event triggers: | ||
Line 35: | Line 35: | ||
*Changing the the timeline by shortening or elongating its duration. | *Changing the the timeline by shortening or elongating its duration. | ||
− | ===Dialogue | + | ===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 43: | Line 43: | ||
*Close | *Close | ||
− | ===Timer | + | ===Timer Events=== |
− | + | RLPyTimer can receive the events below: | |
*Time Out | *Time Out | ||
Line 53: | 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. | ||
− | + | <syntaxhighlight lang="Python"> | |
import RLPy | import RLPy | ||
import time | import time | ||
Line 102: | Line 102: | ||
#-- Start Timer --# | #-- Start Timer --# | ||
timer_event.Start() | timer_event.Start() | ||
− | </ | + | </syntaxhighlight> |
Latest revision as of 00: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:
- Make sure your script imports and uses RLPy or related class.
- Set global variable(s) for event and event callback.
- Register the event and set its corresponding callback
- Overwrite the event callback to the received event
- 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()