Profile Picture

Basic Samples Request thread

Posted By luke (RL) Last Year
You don't have permission to rate!
Author
Message
luke (RL)
luke (RL)
Posted Last Year
View Quick Profile
Junior Member

Junior Member (152 reputation)Junior Member (152 reputation)Junior Member (152 reputation)Junior Member (152 reputation)Junior Member (152 reputation)Junior Member (152 reputation)Junior Member (152 reputation)Junior Member (152 reputation)Junior Member (152 reputation)

Group: Power Developer
Last Active: Yesterday
Posts: 94, Visits: 3.1K
Dear Developer
I'm Luke form reallusion. I'm in charge of this Python project since the end of last year. 
It's not easy to have the scripting ability in iClone, so even we knew there are so many API not available in the first version, we still insist to release to the public and hope to learn from your requests and needs to help us to enhance that.
Except for the API its self, we also understand that good document will help you to get into the swing of it, so this thread we want to gather all your samples request and our team will do it then upload to the github for your reference. So please don't hesitate to offer your request here. 
Please note that in the first run, our team only can support the simple sample requests, such as how to get all the keys from the prop or how to get the selected object etc.
Let's do this! We hope this Python API can extend the ability of iClone and you folks can do various plugins to make a difference of iClone. thanks

last thread update (https://forum.reallusion.com/FindPost400304.aspx)

==================== Sample Request ====================
Kelley - How to get all the keys from Prop. (uploaded 181227)
Kelley - How to get the object selected. (uploaded 181227)
Kelley - How to get the parent object is my other main request. ( we can't do it now, update to our API roadmap ) 
Kelley - How to delete key. (uploaded 181228)
RobertoColombo - How to get mesh data. ( we can't do it now, update to our API roadmap ) 
RobertoColombo - Just to give an example: ShowMessageBox(), and the detailed description of parameters. (uploaded 181228)
videodv - How to change the Transition Curve of a material. ( we can't do it now, update to our API roadmap ) 

Edited
9 days ago by luke (RL)
Kelleytoons
Kelleytoons
Posted Last Year
View Quick Profile
Distinguished Member

Distinguished Member (15.4K reputation)Distinguished Member (15.4K reputation)Distinguished Member (15.4K reputation)Distinguished Member (15.4K reputation)Distinguished Member (15.4K reputation)Distinguished Member (15.4K reputation)Distinguished Member (15.4K reputation)Distinguished Member (15.4K reputation)Distinguished Member (15.4K reputation)

Group: Forum Members
Last Active: 3 hours ago
Posts: 5.3K, Visits: 10.2K
How to get the parent object is my other main request.



Alienware Aurora R7, Win 10, i7-8700k, 4.7GHz CPU, 32GB RAM, GTX Titan XP (12GB), Samsung 960 Pro 2TB M-2 SSD, TB+ Disk space
Mike "ex-genius" Kelley
RobertoColombo
RobertoColombo
Posted Last Year
View Quick Profile
Distinguished Member

Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 1.5K, Visits: 2.9K
Hi,

one thing that would be extremely useful is the possibility to access the mesh data for the various assets (props, terrain, etc.), i.e. vertex coordinates.
For example, if we develop some tools to move an asset, eventually should be possible to avoid intersections with teh terrain or other objects.

In addition, I wish you can have a look at the thread here: https://forum.reallusion.com/399142/Python-FAQ-Tracker
There are several quetsions pointing to gaps and things not clear in the documentation.

Thanks
Regards

  Roberto

My PC:
OS: Windows 10 Pro English 64-bit / CPU: Intel i7-9700 3.6GHz / MB: ASUS ROG Strix Z390  RAM: 16GB DDR4 2.6GHz / HD: 2TB+3TB  /  
SSD: 2x512GB Samsung 860 EVO / 
VB: Palit GTX2080 TI GamingPro 11GB / AB: embedded in the MB and VB (audio from the VB with an HDMI splitter) / DirectX: 12

RobertoColombo
RobertoColombo
Posted Last Year
View Quick Profile
Distinguished Member

Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 1.5K, Visits: 2.9K
Hi,

I am not sure how to start the main,py script when iClone is launched.
1. I created a new folder named "OpenPlugin" under Bin64
2. I created main.py in OpenPlugin folder and copy-pasted the code provided in the doc.
3. Started iClone... nothing happens...

Any idea about what could be wrong ?

  Roberto

My PC:
OS: Windows 10 Pro English 64-bit / CPU: Intel i7-9700 3.6GHz / MB: ASUS ROG Strix Z390  RAM: 16GB DDR4 2.6GHz / HD: 2TB+3TB  /  
SSD: 2x512GB Samsung 860 EVO / 
VB: Palit GTX2080 TI GamingPro 11GB / AB: embedded in the MB and VB (audio from the VB with an HDMI splitter) / DirectX: 12

RobertoColombo
RobertoColombo
Posted Last Year
View Quick Profile
Distinguished Member

Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 1.5K, Visits: 2.9K

Documentation for RUi is largely incomplete.
Just to give an example (but the following is valid for every method): ShowMessageBox()

a. There is no indication aboutwhat is the value type of the input parameters.
      Intuitively the first two are strings but what about the olthers ?
      The "Hello world" Python example uses the value "RLPy.EMsgButton_Ok" => how to link from the doc of this function that this is the value to be used ?
b. The "Hello world" Python example uses 3 input parameters, whereas in teh doc there are listred 5.
       Which one are optional ?
c. Retun is "button status". 
      What does this mean ?
      What are the possible values ?


My PC:
OS: Windows 10 Pro English 64-bit / CPU: Intel i7-9700 3.6GHz / MB: ASUS ROG Strix Z390  RAM: 16GB DDR4 2.6GHz / HD: 2TB+3TB  /  
SSD: 2x512GB Samsung 860 EVO / 
VB: Palit GTX2080 TI GamingPro 11GB / AB: embedded in the MB and VB (audio from the VB with an HDMI splitter) / DirectX: 12

RobertoColombo
RobertoColombo
Posted Last Year
View Quick Profile
Distinguished Member

Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 1.5K, Visits: 2.9K
The "main" problem I have right now is exactly... how to run the "main.py" script at the startup.
I created a new folder under Bin64, named OpenPlugin
Put 'main.py' in there, with teh code provided in the doc.

Nothing happens...

So, I changed the function name to run_script() and manually loaded it.
The script generates this error in the console window: 
   <class 'AttributeError'>, File: E:/WorkingArea/iClone/Python/Main.py, Line: 7

corresponding to the code:

   ic_dlg = PySide2.shiboken2.wrapInstance(int(RLPy.RUi.GetMainWindow()), PySide2.QtWidgets.QMainWindow)


My PC:
OS: Windows 10 Pro English 64-bit / CPU: Intel i7-9700 3.6GHz / MB: ASUS ROG Strix Z390  RAM: 16GB DDR4 2.6GHz / HD: 2TB+3TB  /  
SSD: 2x512GB Samsung 860 EVO / 
VB: Palit GTX2080 TI GamingPro 11GB / AB: embedded in the MB and VB (audio from the VB with an HDMI splitter) / DirectX: 12

Edited
Last Year by RobertoColombo
RobertoColombo
RobertoColombo
Posted Last Year
View Quick Profile
Distinguished Member

Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 1.5K, Visits: 2.9K


I have another issue that i can't get through.
What I want to do is a very simple task: to be able to calla function defined ina certain file from another file.

So, I created a file with a function that print a simple message.
Then, i created another file, with an import statement for the 1st file and a call to that function within run_script().
I am sure that teh file with the function is imported because if i insert some errors there they are displayed during the "import" phase.
Problem is that when I run this script, i get the error "<class 'NameError'>" exactly at the line of code where I call the function defined in the other file.
It looks like iClone can't find this file and the function within it.
The two files are placed in the same directory.

Pls, let us know how to do this, because this is the basis to split the code into different modules

My PC:
OS: Windows 10 Pro English 64-bit / CPU: Intel i7-9700 3.6GHz / MB: ASUS ROG Strix Z390  RAM: 16GB DDR4 2.6GHz / HD: 2TB+3TB  /  
SSD: 2x512GB Samsung 860 EVO / 
VB: Palit GTX2080 TI GamingPro 11GB / AB: embedded in the MB and VB (audio from the VB with an HDMI splitter) / DirectX: 12

RobertoColombo
RobertoColombo
Posted Last Year
View Quick Profile
Distinguished Member

Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 1.5K, Visits: 2.9K
Thanks to "waveact" offline help, the way to run main.py at the start of iClone is now solved!

The way to do that is to have a TWO level folder under Bin64, i.e.: Bin64\OpenPlugin\[here you need to create another folder with any name you want]
In my case I created \OpenPlugin\PythonAPI
Then, within PythonAPI, put the main.py file.

When iClone starts, I can see that it is scanning the available plug ins and at the end also PythonAPI is displayed.
Then the main.py is executed.... but here I still have the problem of this line of code, reported above:
 
   ic_dlg = PySide2.shiboken2.wrapInstance(int(RLPy.RUi.GetMainWindow()), PySide2.QtWidgets.QMainWindow)

so, what I did so far is to have a main.py with just one print() inside the initialize_plugin() function, i.e.

import RLPy

def initialize_plugin():
    print("Ciao")

when iClone starts, I can see "Ciao" displayed in the Python console.

Now that iClone can recognize the main.py script at teh start-up, I tried to insert in it a call to a function placed into another script, saved in the same \OpenPlugin\PythonAPI directory.
Even in this can nothing happens, so I still have no idea how to split the code among different files...

My PC:
OS: Windows 10 Pro English 64-bit / CPU: Intel i7-9700 3.6GHz / MB: ASUS ROG Strix Z390  RAM: 16GB DDR4 2.6GHz / HD: 2TB+3TB  /  
SSD: 2x512GB Samsung 860 EVO / 
VB: Palit GTX2080 TI GamingPro 11GB / AB: embedded in the MB and VB (audio from the VB with an HDMI splitter) / DirectX: 12

Edited
Last Year by RobertoColombo
RobertoColombo
RobertoColombo
Posted Last Year
View Quick Profile
Distinguished Member

Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)Distinguished Member (6.0K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 1.5K, Visits: 2.9K
main.py issue is now solved.

Two more lines of codes are needed, otherwise iClone is not able to see the elements within PySide2
The additional code is:

from PySide2.QtWidgets import QMainWindow, QMenu
from PySide2.shiboken2 import wrapInstance

The same issue is the root cause of the problem i experienced when trying to execute a function located into another file.
By adding an explicit import form that file, the function is now visible, that is:

module2.py comtains

def Test():
    print("Some text...")

module1.py contains

import RLPy
import module2
from module2 import Test
def run_script():
    Test()


adding the code "from module2 import Test" makes Test() visible to module1


My PC:
OS: Windows 10 Pro English 64-bit / CPU: Intel i7-9700 3.6GHz / MB: ASUS ROG Strix Z390  RAM: 16GB DDR4 2.6GHz / HD: 2TB+3TB  /  
SSD: 2x512GB Samsung 860 EVO / 
VB: Palit GTX2080 TI GamingPro 11GB / AB: embedded in the MB and VB (audio from the VB with an HDMI splitter) / DirectX: 12

jlittle
jlittle
Posted Last Year
View Quick Profile
Distinguished Member

Distinguished Member (3.1K reputation)Distinguished Member (3.1K reputation)Distinguished Member (3.1K reputation)Distinguished Member (3.1K reputation)Distinguished Member (3.1K reputation)Distinguished Member (3.1K reputation)Distinguished Member (3.1K reputation)Distinguished Member (3.1K reputation)Distinguished Member (3.1K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 1.4K, Visits: 11.2K
I realize that not everyone attempting to use Python and the RL API is a programmer so here are some thoughts for you:

When creating your folder names under "Bin64\OpenPlugin\[yourapiname]" keep in mind that this is probably where everybody's project folders will be placed when you download/purchase them in the future so be sure to create a unique name for your folder so that it hopefully will not conflict with other dev's folder names. You should also put all your files/modules in the same folder for that project.

You should always put in your main.py file a comment line that indicates the version of your code. When you have many users of your code, knowing what version they are using helps in tracking down issues.
I also put on each versions comment line the date of that version and what the changes were. Typically you will change a version number after each release.
Ex:
#V1.0.0 12/23/18 Created
#V1.0.1 12/27/18 Fixed .....

The version number could also be displayed in an "About" menu selection, if using menus, or just displayed in one of your panels somewhere.
You could also create a text file in your folder with the version info.
Keep in mind that not everyone using your project will be savy about how to find the version info so try to make it easy for them.

Since each folder has only one (1) main.py file, you will need multiple folders for multiple projects or you can provide a menu of your multiple projects/functions and contain all the files for those functions in one folder.

Yes, you must "import" into a file any external files that contain items that are referenced from that file.
The "import" makes visible the items in the external file to the file importing it. This is a standard practice.

Other programming standards for Python are as follows:

Naming

  • Variables, functions, methods, packages, modules
    • lower_case_with_underscores
  • Classes and Exceptions
    • CapWords
  • Protected methods and internal functions
    • _single_leading_underscore(self, ...)
  • Private methods
    • __double_leading_underscore(self, ...)
  • Constants
    • ALL_CAPS_WITH_UNDERSCORES
General Naming Guidelines

Avoid one-letter variables (esp. l, O, I).

Exception: In very short blocks, when the meaning is clearly visible from the immediate context


Indentation

Use 4 spaces--never tabs. Enough said.

Imports

Import entire modules instead of individual symbols within a module. For example, for a top-level module canteen that has a file canteen/sessions.py,

Yes

import canteenimport canteen.sessionsfrom canteen import sessions

No

from canteen import get_user  # Symbol from canteen/__init__.pyfrom canteen.sessions import get_session  # Symbol from canteen/sessions.py

Exception: For third-party code where documentation explicitly says to import individual symbols.


Put all imports at the top of the page with three sections, each separated by a blank line, in this order:
  1. System imports
  2. Third-party imports
  3. Local source tree imports

Rationale: Makes it clear where each module is coming from.


On comments

Use them sparingly. Prefer code readability to writing a lot of comments. Often, small methods are more effective than comments.


For more info on Python Style see HERE and/or HERE

Jeff


See my CTA Tutorials on the YouTube channel CTAStepByStep
Check out EZColors for CTA. The easy way to change Render Styled (RS) colors.




Reading This Topic