Difference between revisions of "IC Python API:Loading All Props"
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 (→Loading All Template Props) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{TOC}} | {{TOC}} | ||
{{Parent|IC_Python_API:RL_Python_Samples|RL Python Samples}} | {{Parent|IC_Python_API:RL_Python_Samples|RL Python Samples}} | ||
+ | |||
+ | This article will go over the use of Python '''os''' and '''winreq''' to load all props within the iClone Template directory. Learn how to deal with and access the Window's file system with Python. | ||
== Necessary Modules == | == Necessary Modules == | ||
Line 32: | Line 34: | ||
# Drill down to the beveled shapes directory | # Drill down to the beveled shapes directory | ||
path = ic_template_path + r"\iClone Template\Props\3D Blocks\Beveled" | path = ic_template_path + r"\iClone Template\Props\3D Blocks\Beveled" | ||
− | </ | + | </syntaxhighlight> |
== Loading All Template Props == | == Loading All Template Props == | ||
− | With the template folder path, we can search the directory for all '''iProps'''. | + | With the template folder path, we can search the directory for all '''iProps''', load them into iClone, assemble them in a single line, and scale them down to stand side-by-side. |
<syntaxhighlight lang="Python"> | <syntaxhighlight lang="Python"> | ||
Line 66: | Line 68: | ||
index += 1 | index += 1 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | [[File:Iclone_python_api_loading_all_props_01.png]] | ||
== Everything Put Together == | == Everything Put Together == | ||
Line 119: | Line 123: | ||
* [[ 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> |
Latest revision as of 00:05, 21 May 2019
- Main article: RL Python Samples.
This article will go over the use of Python os and winreq to load all props within the iClone Template directory. Learn how to deal with and access the Window's file system with Python.
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"
Loading All Template Props
With the template folder path, we can search the directory for all iProps, load them into iClone, assemble them in a single line, and scale them down to stand side-by-side.
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.