IC Python API:Your First iClone Python Plugin
- Main article: iClone Python API.
This topic will guide you through the creation and execution of your first iClone Python plugin.
Preparing your Python IDE
iClone doesn't support an internal IDE, so you'll have to resort to an external script editor like Notepad++, PyCharm, Spyder, among others.
We recommend Notepad++, it's a free and tiny source code editor with Python support. Before using Notepad++, you should enable Replace by space option under Settings > Preferences > Language > Tab Settings.
We recommend setting tab sizes to 4 spaces.
Loading your Python Plugin
There are two different methods for loading a plugin into iClone:
Method 1: Create a main.py file and put it inside the iClone Install Directory \ Bin64 \ OpenPlugin folder\ [Your Plugin Name] The PY files requires one specific functions: initialize_plugin(), which is respectively called when iClone attempts to load the plugin. If this functions do not exist in the file, the plugin will fail to load. The name of PY file must be main.py.
Code:import RLPy import PySide2 from PySide2 import * from PySide2.shiboken2 import wrapInstance 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(show_dialog) def show_dialog(): RLPy.RUi.ShowMessageBox("Your First Python Plugin", "Hello World", RLPy.EMsgButton_Ok)
Method 2: Manually perform Menu > Script > Load Python, choose a PY file then make sure the initial define resembles the following:
Code:import RLPy def run_script(): print ("Hello World") RLPy.RUi.ShowMessageBox("Your First Python Plugin", "Hello World", RLPy.EMsgButton_Ok)