Python FAQ Tracker


https://forum.reallusion.com/Topic399142.aspx
Print Topic | Close Window

By RobertoColombo - 2 Years Ago
Hi,

I thought it might be useful to insert in a single thread all the questions & doubts that will come out while developing Python plug-ins.
The idea is simple: put a number before the text and let's have RL answering them one by one.
Hereafter are the first ones that popped up after approaching iClone Python for few minutes.

Cheers

  Roberto
By Kelleytoons - 2 Years Ago
You tried this on the default male dummy avatar?

Hmmm, that's pretty weird then.  I wonder why Luke would say that it was broken.

Edit: Nope, just tested myself.  Still broken.  I assume you're not testing correctly.  If you get this to work please post a video showing it so we can see what you are doing differently (put the motion dummy_male in a scene and run the code).

(And even on other avatars it is hit and miss -- sometimes it makes them disappear, other times it only removes the skin but not the clothing. Either way, code not working, and the devs agree).
By luke (RL) - 2 Years Ago
RobertoColombo (12/26/2018)
1. Where shall we put the main.py Pythin file ?
    The doc is not clear: shall we create a new folder called "OpenPlugin" ?

Yes, you need to create OpenPlugin folder under your [iClone Install Path]/Bin64/, but if you have MotionLIVE installed, that should be there.

2. in order to use Qt libs, shall we install the whole Qt package or are already part of iClone 7.4 setup files ?

Yes, it is part of iClone 7.4.

3. Shall we download and install pyside2 and shiboken2 or are already part of iClone 7.4 setup files ?

Yes, it is part of iClone 7.4.
By SeanMac - 2 Years Ago
@zeronimo

Thanks for that
By RobertoColombo - 2 Years Ago
4. Documentation for RUi is largely incomplete.
Just to give an example: ShowMessageBox()

4a. 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 ?
4b. The "Hello world" Python example uses 3 input parameters, whereas in teh doc there are listred 5.
       Which one are optional ?
4c. Retun is "button status".
      What does this mean ?
      What are the possible values ?
By RobertoColombo - 2 Years Ago
1. Where shall we put the main.py Pythin file ?
    The doc is not clear: shall we create a new folder called "OpenPlugin" ?
2. in order to use Qt libs, shall we install the whole Qt package or are already part of iClone 7.4 setup files ?
3. Shall we download and install pyside2 and shiboken2 or are already part of iClone 7.4 setup files ?

By Kelleytoons - 2 Years Ago
Oh, and note that any avatars this DOES work on would also work with the original code I posted.  Once again, your code does nothing different, only collects them all in a list which may or may not be accurate depending on the avatar.

So, to reiterate, the basic issue is that *some* avatars (and, I guess, some clothing) will return an error when GetMaterial is called.  That's why even a [0] call to the first item in the list can throw an error.  This should *never* happen (because all avatars, as well as all props, have SOME material assigned to them.  If it's only 1 then the [0] call will work).

Your code just confuses the issue and I don't know how to explain it any more clearly than that.  So I won't be revisiting this topic.
By luke (RL) - 2 Years Ago
RobertoColombo (12/26/2018)
5. Which events and associated methods are triggered when main.py is executed ?
Only initialize_plugin() or others ?

It's not the event, the initialize_plugin function will be executed when iClone load main.py file in OpenPlugin folder. Must remember that the iClone only execute the initialize_function with the py file called "main.py",

6. Which events and associated methods are triggered when a Python script is loaded and executed ?
Only run_script() or others ?

Same as above, the run_script() will be executed when you use "Load Python" in the menu

By Kelleytoons - 2 Years Ago
No, you're missing the point but let me try and explain it again.

Your program doesn't produce any errors because it doesn't do anything.  The error that comes up when the sample program is run is because the function to return GetMaterialNames doesn't actually return anything.  It's returning an array of length 0, which is why your loop through isn't even executed once.

However, that call MUST produce at least one material name, which is why in the sample they use the zero index [0].  Try and and you'll see.  You cannot have an object without at least one material, and this function WILL work on the female avatar, just not on the male.  The RL devs have already reported this is a problem and they will fix it.

So, to sum up, you didn't need to rewrite the code -- the sample code I quoted should work fine as it is, but it will not due to an error in the Python API.  Hope you can understand it now.

Opps -- missed the question in your response.  IOW is netspeak for "in other words".  Sorry -- I'm not always up on the abbreviations myself.

Here's something else to prove your code doesn't work -- just alter it to change the opacity of all the materials in an avatar to 0.  Here's the relevant line:

material_component.AddOpacityKey(RLPy.RGlobal.GetTime(), mesh_name, material_name,0)

If your code works, then any avatars in the scene will turn invisible.

By Delerna - 2 Years Ago
7. Is it possible to make a python API code automatically load when a prop/character/??? gets loaded into a project?

Just thinking I may at some stage write a plugin that applies to a particular object I create in order to make it easy for users to do something that is particular for the thing I created and having it load when they automatically load the object saves them (and me) having to remember to also load the plugin. 
  



EDIT
Gee I hate how the forum does this. While typing a post, if you copy and paste some text the texts color looks correct but when you update the post the text's color ends up the same color as the background.....crazy

By wires - 2 Years Ago
justaviking (12/27/2018)
Kelleytoons (12/27/2018)
This isn't the only example but it's typical -- were these samples not tested?


Did you have to ask?

Allow me rephrase the question:  "Why were these not tested?"


Maybe they don't have any testers available. ๐Ÿ˜

By justaviking - 2 Years Ago
wires (12/27/2018)
justaviking (12/27/2018)
Kelleytoons (12/27/2018)
This isn't the only example but it's typical -- were these samples not tested?

Did you have to ask?
Allow me rephrase the question:  "Why were these not tested?"

Maybe they don't have any testers available. ๐Ÿ˜


Of course, that must be it.  Nobody willing to test.  What a shame.  <end sarcasm>

By Zeronimo - 2 Years Ago
Kelleytoons (12/27/2018)
I'm having just basic issues with even sample code provided.  We have this in the docs:

avatar_list = RLPy.RScene.GetAvatars()
avatar = avatar_list[0]
material_component = avatar.GetMaterialComponent()
mesh_list = avatar.GetMeshNames()
mesh_name = mesh_list[0]
material_list = material_component.GetMaterialNames(mesh_name)
material_name = material_list[0]

and it doesn't work, throwing an error at the last line (
<class 'IndexError'>Wink.  So either I'm completely stupid (always a possibility) or the docs are just wrong (my bet).

This isn't the only example but it's typical -- were these samples not tested?


I tested this same sample, and like you I had the same mistakes. I still have not found why.
But I rewrote the code completely, with some improvements, and it works perfectly.

see attachments
Py file
Log file

By Zeronimo - 2 Years Ago
I have to leave for a few hours, but when I come back I will make a video.
I quickly did a test with Motion_dummy_male and actually it does not work with this avatar. on the other hand with Motion_dummy_female it works.
By luke (RL) - 2 Years Ago
RobertoColombo (12/26/2018)
4. Documentation for RUi is largely incomplete.
Just to give an example: ShowMessageBox()

4a. 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 ?
4b. The "Hello world" Python example uses 3 input parameters, whereas in teh doc there are listred 5.
       Which one are optional ?
4c. Retun is "button status".
      What does this mean ?
      What are the possible values ?


move to "Basic Sample Request" thread, thanks

By Kelleytoons - 2 Years Ago
No, that doesn't work for me either.

All you really did in your code was ignore the fact there are no materials in the material_list array (IOW, that is wrong -- there ARE materials there, but your code says if it comes back nil then ignore.  The basic issue is still there, which is the code fragment doesn't work because GetMaterialNames doesn't work).
By Zeronimo - 2 Years Ago
here is the video.
apart for motion_dummy_male, we see that for other avatars are the clothes and accessories that do not work.
I do not know if the problem is due to Python or rather to avatars, clothes and accessories. I leave it to the developers of Reallusion to see that.




By Kelleytoons - 2 Years Ago
I'm having just basic issues with even sample code provided.  We have this in the docs:

avatar_list = RLPy.RScene.GetAvatars()
avatar = avatar_list[0]
material_component = avatar.GetMaterialComponent()
mesh_list = avatar.GetMeshNames()
mesh_name = mesh_list[0]
material_list = material_component.GetMaterialNames(mesh_name)
material_name = material_list[0]

and it doesn't work, throwing an error at the last line (
<class 'IndexError'>Wink.  So either I'm completely stupid (always a possibility) or the docs are just wrong (my bet).

This isn't the only example but it's typical -- were these samples not tested?
By Zeronimo - 2 Years Ago
Kelleytoons (12/28/2018)
No, you're missing the point but let me try and explain it again.

Your program doesn't produce any errors because it doesn't do anything.  The error that comes up when the sample program is run is because the function to return GetMaterialNames doesn't actually return anything.  It's returning an array of length 0, which is why your loop through isn't even executed once.

However, that call MUST produce at least one material name, which is why in the sample they use the zero index [0].  Try and and you'll see.  You cannot have an object without at least one material, and this function WILL work on the female avatar, just not on the male.  The RL devs have already reported this is a problem and they will fix it.

So, to sum up, you didn't need to rewrite the code -- the sample code I quoted should work fine as it is, but it will not due to an error in the Python API.  Hope you can understand it now.

Opps -- missed the question in your response.  IOW is netspeak for "in other words".  Sorry -- I'm not always up on the abbreviations myself.

Here's something else to prove your code doesn't work -- just alter it to change the opacity of all the materials in an avatar to 0.  Here's the relevant line:

material_component.AddOpacityKey(RLPy.RGlobal.GetTime(), mesh_name, material_name,0)

If your code works, then any avatars in the scene will turn invisible.



I introduced the new instruction into the program, and at home all the avatars of the scene become effectively invisible.
for me it works, I do not understand why it does not work for you.





By RobertoColombo - 2 Years Ago
5. Which events and associated methods are triggered when main.py is executed ?
Only initialize_plugin() or others ?

6. Which events and associated methods are triggered when a Python script is loaded and executed ?
Only run_script() or others ?
By Zeronimo - 2 Years Ago
Kelleytoons (12/27/2018)
No, that doesn't work for me either.

All you really did in your code was ignore the fact there are no materials in the material_list array (IOW, that is wrong -- there ARE materials there, but your code says if it comes back nil then ignore.  The basic issue is still there, which is the code fragment doesn't work because GetMaterialNames doesn't work).



Sorry, I do not see where the problem is, maybe because English is not my language, but when I run this program the console does not report any errors.
- material_list contains an array of materials
- GetMaterialNames returns the name of the material
if you look at the log file you will see that this data is present.
This is my first program in Python, maybe I do not understand everything, it's also possible.

what does IOW mean?
By Kelleytoons - 2 Years Ago
The same problem occurs for prop materials (GetProps) as well (some work, some do not -- most do not).  The devs are aware.
By justaviking - 2 Years Ago
Kelleytoons (12/27/2018)
This isn't the only example but it's typical -- were these samples not tested?


Did you have to ask?

Allow me rephrase the question:  "Why were these not tested?"