Difference between revisions of "IC Python API:Loading All Props"
From Reallusion Wiki!
Chuck (RL) (Talk | contribs) (Created page with "{{TOC}} {{Parent|IC_Python_API:RL_Python_Samples|RL Python Samples}} == Necessary Modules == Besides the RLPy standard module, we'll need two system based modules to load a...") |
Chuck (RL) (Talk | contribs) m (→APIs Used) |
||
Line 119: | Line 119: | ||
* [[ IC_Python_API:RLPy_RFileIO#LoadFile | RLPy.RFileIO.LoadFile() ]] | * [[ IC_Python_API:RLPy_RFileIO#LoadFile | RLPy.RFileIO.LoadFile() ]] | ||
* [[ IC_Python_API:RLPy_RScene#FindObject | RLPy.RScene.FindObject() ]] | * [[ IC_Python_API:RLPy_RScene#FindObject | RLPy.RScene.FindObject() ]] | ||
− | |||
* [[ IC_Python_API:RLPy_RTime | RLPy.RTime() ]] | * [[ IC_Python_API:RLPy_RTime | RLPy.RTime() ]] | ||
* [[ IC_Python_API:RLPy_RVariant | RLPy.RVariant() ]] | * [[ IC_Python_API:RLPy_RVariant | RLPy.RVariant() ]] | ||
</div> | </div> |
Revision as of 23:57, 20 May 2019
- Main article: RL Python Samples.
Necessary Modules
Besides the RLPy standard module, we'll need two system based modules to load a prop from a directory with the likes of os and winreg.
import RLPy
import os
import winreg
os
The os module provides a portable way of using operating system dependent functionality. For more information, see os.html
winreg
winreg offers functions that exposes the Windows registry API to Python. For more information, see winreg.html
Template Folder Path
Let's get the directory path for the iClone Template folder.
# 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])
# Drill down to the beveled shapes directory
path = ic_template_path + r"\iClone Template\Props\3D Blocks\Beveled"
</syntaxhighligh>
== Loading All Template Props ==
With the template folder path, we can search the directory for all '''iProps'''.
<syntaxhighlight lang="Python">
index = 0
for file_name in os.listdir(path):
if file_name.endswith(".iProp"): # If the file is an iProp
# Load the prop into the scene
RLPy.RFileIO.LoadFile(path+"\\"+file_name)
# Grab the loaded prop by name
prop = RLPy.RScene.FindObject(RLPy.EObjectType_Prop, os.path.splitext(file_name)[0])
# Retrieve the transform datablock to move the prop where we desire
prop_control = prop.GetControl("Transform")
data_block = prop_control.GetDataBlock()
# Align the props side by side
data_block.SetData("Position/PositionX", RLPy.RTime(0),
RLPy.RVariant(index * 50 - 280))
# Scale the props down
data_block.SetData("Scale/ScaleX", RLPy.RTime(0), RLPy.RVariant(0.4))
data_block.SetData("Scale/ScaleY", RLPy.RTime(0), RLPy.RVariant(0.4))
data_block.SetData("Scale/ScaleZ", RLPy.RTime(0), RLPy.RVariant(0.4))
# Increment the index for placing the next prop
index += 1
Everything Put Together
You can copy and paste the following code into a PY file and load it into iClone via Script > Load Python.
import RLPy
import os
import winreg
# 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])
# Drill down to the beveled shapes directory
path = ic_template_path + r"\iClone Template\Props\3D Blocks\Beveled"
index = 0
for file_name in os.listdir(path):
if file_name.endswith(".iProp"): # If the file is an iProp
# Load the prop into the scene
RLPy.RFileIO.LoadFile(path+"\\"+file_name)
# Grab the loaded prop by name
prop = RLPy.RScene.FindObject(RLPy.EObjectType_Prop, os.path.splitext(file_name)[0])
# Retrieve the transform datablock to move the prop where we desire
prop_control = prop.GetControl("Transform")
data_block = prop_control.GetDataBlock()
# Align the props side by side
data_block.SetData("Position/PositionX", RLPy.RTime(0),
RLPy.RVariant(index * 50 - 280))
# Scale the props down
data_block.SetData("Scale/ScaleX", RLPy.RTime(0), RLPy.RVariant(0.4))
data_block.SetData("Scale/ScaleY", RLPy.RTime(0), RLPy.RVariant(0.4))
data_block.SetData("Scale/ScaleZ", RLPy.RTime(0), RLPy.RVariant(0.4))
# Increment the index for placing the next prop
index += 1
APIs Used
You can research the following references for the APIs deployed in this code.