Profile Picture

My first Trials Of Getting A Python Script Working

Posted By Delerna 6 Years Ago
Rated 5 stars based on 1 vote.
Author
Message
Delerna
Delerna
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)

Group: Forum Members
Last Active: 2 Years Ago
Posts: 1.5K, Visits: 14.8K
Been reading the iClone Python API  especially the bit that opens up from the link I find a little confusing. The whole lot of it is not very clear to me so I will be doing a lot of experimenting with codes so I can eventually figure out what reallusion are trying to say. I also intend joining the other people who will be posting the things as we figure them out because maybe it might assist others who also find it difficult to fully understanding due to the way its written. Also the things posted by other people may help me get the use of this API clear in my head.

SOME POINTS AS I UNDERSTAND SO FAR

The way I read it the first method where we save the python file here iClone Install Directory \ Bin64 \ OpenPlugin folder\       [Your Plugin Name]  and it must be names Main.py suggests to me that this is a python file that will automatically load into iClones menu bar named Plugins whenever we load iClone. The fact that the python file must be named Main.py suggests to me that there can only ever be 1 python file that will automatically load when we load iClone. So the way I am thinking on that is if we want more make more than one that will automatically load we will need to remove the one we don't want and add the one we do want before we load iClone. Maybe there is a way to have that single main.py file list all python plugins we want to automatically load in when we start iclone but I'm only guessing so far. Its also not very clear to me how the folder for python plugins in Bin64 needs to be named. I see there is a folder named plugin in there. But the document says OpenPlugin Folder. Not sure yet  So, I am ignoring this first method at the moment. I will get into it later as I get to understand how to write python addons for iClone better.

As I understand it the second method means we can create as many python addons as we want and we can name and save them however we want. All we need to do is Load iClone first and then click the Menu bar named Script, click Load Python navigate to the folder where we save them and double click the one we want to load. Repeatedly load as many as we need for the project we are working on. Auto loading might be better but this way suits me at the moment because I don't have to restart iClone to reload a python addon after I have modified the code. Just reload the file after I have modified it using the Script menu bar. One problem with that is the previous one loaded doesn't get replaced and the only way to remove it is to close and restart iClone. At least, that's all I have found for removing them from the Plugins menu bar so far. So making a change to the code and reloading it say 10 times ends up with that plugin being listed in the plugins menu bar 10 times. I wish the one we load from the Script menu bar would just replace rather than add one in the Plugins menu bar if it has the same name.

Anyway, enough of the beginning points. I am now working on adding how I got my first attempt working as far as I can tell.
I haven't fully tested it but it loads and displays the user interface when I select it in the plugins menu bar.
I will also be showing my first attempts that didn't work and why they didn't work. In Script menu bar there is a Console Log that displays errors returned to iClone by python. Took me a little bit of experimenting to understand this but its starting to help me figure out what is wrong with the code.

Working on publishing this in the next comment for this post now. Should have it done in an hour or so.
Looking forward reading replies from anyone  for comments, suggestions or notified bad thinking on my side.
I'm in the learning process of using  python as an API for iClone.


i7-3770 3.4GHz CPU 16 GB Ram   
GeForce GTX1080 TI 11GB
Windows 10 Pro 64bit
Edited
6 Years Ago by Delerna
Delerna
Delerna
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)

Group: Forum Members
Last Active: 2 Years Ago
Posts: 1.5K, Visits: 14.8K
BATCH RENDER FOLDER
Ok I want to learn how to make my own UI for python plugins I end up wanting to make (i'm in learning mode now so not actually making anything yet)

1) So I went to this  clicked the required files link and clicked the main.py link to check the code.
2) Next I clicked the Raw button at the top of the code to remove the line numbers
3) I then selected all the code and copied it.
4) Went to my folder where Im saving all my iClone python plugins and created a text file.
5) Renamed it to   BatchRenderFolder.py    (not main.py because I don't want to do it that way yet)
6) I then loaded the file into Notepad++      (I like using this)
7) Then I pasted the code I copied into the file and saved it
8) Now, because I want to do it with method 2 and not method 1 (as shown here) I did this
    a) Method 1 must have a function named as  def initialize_plugin():
        Method 2 must have a function names as   def run_Script():
        So I renamed the initialize_plugin function to run_Script to suit the way it needs to be for method 2
   b) I noticed at the bottom of the code there was another function also called run_Script that simply called the initialize_plugin fuction.
       So it became obvious to me, in reality even method 1 is run initially by run_Script and not initialize_plugin. Hmmmmm, maybe I could have just left the code as it was?
       Anyway, I just deleted the run_Script function at the bottom and its call to initialize_plugin and left the one at the top changed to run_Script.
9) Finally I loaded the file into iClone after I opened it and here is the result. Double click it to see the full size of it.

https://forum.reallusion.com/uploads/images/8627c622-85e1-4646-ba1e-65cb.png

Yep, errors. After checking the error codes to see which lines were generating the errors I saw there are other things in this link that are being used by it that I haven't included. But also the way its written I needed to change to suit my style.

So 
1)   I opened the BatchRender.ui file on the site, removed the line numbers, copied the code, created a text file and renamed it the same as this, opened it into Notepad++, passed the code into it and saved it. 
      I then went back to the site, opened the icon folder, clicked the load.svg link right clicked the image and saved it to my iClone python folder.

2)   Then I changed line 70 from this       ui_file = QFile(os.path.dirname(__file__) + "/BatchRender.ui")
                                                to this       ui_file = QFile("E:/Reallusion7/Pythons/BranchRenderFold/BatchRender.ui")



3)   Finally I changed line 85 
                     from this     ui_sel_folder_btn.setIcon(QPixmap(os.path.dirname(os.path.abspath(__file__))+"\\icon\\Load.svg"))
                         to this     ui_sel_folder_btn.setIcon(QPixmap("E:\\Reallusion7\\Pythons\\BranchRenderFold\\icon\\Load.svg"))

And here is the result. Again, double click it to see full size.
https://forum.reallusion.com/uploads/images/7883486e-9f8f-4552-8cd3-a44b.png


OK, that's good enough for me to spend time now figuring out and experimenting with creating User Interface plugins. And then I will need to start looking into understand the code styles and names used for making it do things with animations etc etc. And finally when I am familiar with all that I will actually start making things that I see will be useful.




i7-3770 3.4GHz CPU 16 GB Ram   
GeForce GTX1080 TI 11GB
Windows 10 Pro 64bit
Edited
6 Years Ago by Delerna
Delerna
Delerna
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)

Group: Forum Members
Last Active: 2 Years Ago
Posts: 1.5K, Visits: 14.8K
More coming later

i7-3770 3.4GHz CPU 16 GB Ram   
GeForce GTX1080 TI 11GB
Windows 10 Pro 64bit
SeanMac
SeanMac
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (5.2K reputation)Distinguished Member (5.2K reputation)Distinguished Member (5.2K reputation)Distinguished Member (5.2K reputation)Distinguished Member (5.2K reputation)Distinguished Member (5.2K reputation)Distinguished Member (5.2K reputation)Distinguished Member (5.2K reputation)Distinguished Member (5.2K reputation)

Group: Forum Members
Last Active: Last Year
Posts: 416, Visits: 3.4K
Hi Delerna

It's all dead useful.

Keep 'em coming.

And thanks for your industry.

Home Built in Coolermaster ATX case with GigabyteGA-Z170X-GAMING 7 MoBo, i7-6700 @ 3.4 Ghz, Asus GeForce GTX 1080 Ti GraphicsCard, 32Gb DDR4 RAM, an Acer CB241HQK  & a Samsung S24D300 monitor, Huion H610Pro Graphics Tablet, Kinect v2, Logitech C920 Webcam, Win 10 64 Bit OS

Edited
6 Years Ago by SeanMac
Tony (RL)
Tony (RL)
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)

Group: Administrators
Last Active: 4 Years Ago
Posts: 222, Visits: 1.7K
Delerna (12/26/2018)
More coming later


Hi Delerna,

Thank you so much for helping us to clarify many details.

You have provided so many good explanations. R
eally like a Python Superman!

Reallusion Python Team will continuously polish our documentation based on users' feedback.



                                                          
Tony
Product Marketing Manager 

www.reallusion.com
Edited
6 Years Ago by Tony (RL)
jarretttowe
jarretttowe
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (4.8K reputation)Distinguished Member (4.8K reputation)Distinguished Member (4.8K reputation)Distinguished Member (4.8K reputation)Distinguished Member (4.8K reputation)Distinguished Member (4.8K reputation)Distinguished Member (4.8K reputation)Distinguished Member (4.8K reputation)Distinguished Member (4.8K reputation)

Group: Forum Members
Last Active: 2 Years Ago
Posts: 560, Visits: 3.0K
Can python switch between idle animations? Here is my example that I am wondering:
If I made 3 or 4 idle animations for people who were agitated (angry), could i make a button that immediately put everyone in the scene into those idle animations randomly?
I am basically thinking of emotion controls in this case.
RobertoColombo
RobertoColombo
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (10.7K reputation)Distinguished Member (10.7K reputation)Distinguished Member (10.7K reputation)Distinguished Member (10.7K reputation)Distinguished Member (10.7K reputation)Distinguished Member (10.7K reputation)Distinguished Member (10.7K reputation)Distinguished Member (10.7K reputation)Distinguished Member (10.7K reputation)

Group: Forum Members
Last Active: 3 Years Ago
Posts: 1.6K, Visits: 3.0K
Hi,

Method 1 definitively looks like a way to run a main piece of code, "godfather" of other funtions, which obviusly shall be selectable in some ways, e.g. a GUI.
The example proposes a way to plug additional Python code as a simple menu selection.

Problem is that I found no way to run this main.py...
I tried to set that main.py code into a newly created directory under Bin64, called OpenPlugin... nothing happened.
Then, I tried to move main.py under the already existing Plugin directory, nothing happened again.
I will wait for RL to give some clarification because the documentation is obviously not clear.
I opened a thread for this and future doubts... listing them there should make things clearer for everybody.

Now, I see you already tried to run the code provided into method 1 as a run-time loaded Python code (method 2).
What you see is expected: i do not think you can hope to avoid menu item duplications because that's probably handled by Qt GUI.

Let's see what teh code does...
First a handle for iClone window is retrieved.
With that handle, a new memu group is created, as shown in your pictures.
Then, under this new menu group, an entry is created, called "Hello world" and this entry is connected to the function "show_dialog()", which is activated only when the menu entry is selected.
If you run the same Python file a second time, the "findChild" function will find the Python menu group and won't create it again... but if you want to avoid "Hello wolrd" to be duplicated you should probably add some code that checks whether a menu item (called "menu action") with that name already exists... not sure whether we have it.

This main.py code is just an exmaple to show how to add multiple Python funtions, selectable via a simple menu interface.
My target is obviously to have them loaded one time only, at teh startup, once RL will explain us how to do that: then there will be no duplication!

Cheers

  Roberto



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

Edited
6 Years Ago by RobertoColombo
Delerna
Delerna
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)

Group: Forum Members
Last Active: 2 Years Ago
Posts: 1.5K, Visits: 14.8K
Tony (RL) (12/26/2018)

Hi Delerna,
Thank you so much for helping us to clarify many details.
You have provided so many good explanations. Really like a Python Superman!
Reallusion Python Team will continuously polish our documentation based on users' feedback.


Thanks Tony. In my entire life as a software developer I have always tried to explain things steering clear of using professional wording with using simple wording instead.
Whether that's a good idea or not is something we all need to decide for ourselves. Probably one reason I do that is I have never done any professional training for programming, I taught myself how to program and eventually google came to the internet and I started using that to learn more. So I have never been into professional wordings for explaining things. 25 years ago I started working in IT as a developer and now I am a Software development manager for the company I work for. At least, I was because I retired from it 1 week ago. So now I am getting more fully into creating 3D models and also wanting to get into this for the rest of my life. 

The point of what I am saying is that I have created programming applications for managers in the company I worked for to write their own simple reports to help me have more time  for writing the higher level applications they wanted, Such for quotation creaters, ERP updaters etc. Any they were non-programmers but explaining things simply without using pro-words helped them to write their own and I just published them on our intranet site for all workers who needed it. And they did quite well.

So, I am looking forward to Reallusion's Python Team continuously polishing your documentation and hopping to see things explained well because it will certainly help me. Having to rely on how I understand what is said can easily take me down the wrong track of understanding. Just commenting here and not complaining. I certainly understand it takes a lot of work and time on your behalf putting explanations into documents that helps new users to understand how to use something.

So I am highly looking forward to seeing more explanations on this, iClone python API, from the people who designed it. You will certainly help me improve my use of it.



i7-3770 3.4GHz CPU 16 GB Ram   
GeForce GTX1080 TI 11GB
Windows 10 Pro 64bit
Edited
6 Years Ago by Delerna
Delerna
Delerna
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)Distinguished Member (8.5K reputation)

Group: Forum Members
Last Active: 2 Years Ago
Posts: 1.5K, Visits: 14.8K
Roberto Colombo
Yes method 1. I never tried doing the things you tried for that method because I expected I would get the same results you did. So I didn't bother yet. The important thing for me at the moment is getting my head to understand the coding methods for use within iClone. 

You maybe right? maybe there is a way in the code to check whether the addon already exists so replace it. I actually tried another example last night and it ran when I loaded it and it didn't get added to the plugins menu bar so it certainly looks like there is code int there that does this and its not done by iClone as I first thought.

Looking into understanding the addon's coding now that I know how to load them into iClone.
Will also certainly be watching the forum to see what other people have discovered.


i7-3770 3.4GHz CPU 16 GB Ram   
GeForce GTX1080 TI 11GB
Windows 10 Pro 64bit
justaviking
justaviking
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (20.9K reputation)Distinguished Member (20.9K reputation)Distinguished Member (20.9K reputation)Distinguished Member (20.9K reputation)Distinguished Member (20.9K reputation)Distinguished Member (20.9K reputation)Distinguished Member (20.9K reputation)Distinguished Member (20.9K reputation)Distinguished Member (20.9K reputation)

Group: Forum Members
Last Active: 6 Months Ago
Posts: 8.2K, Visits: 26.5K
@Delerna,

1) Congratulations on the recent retirement.  w00t  It's great that the iClone community will be able to benefit from your new-found free time.  Wink

2) I totally agree about the "non-pro language" approach.  I'm not a real programmer (I've been a hack at varying levels), but I've worked on software projects and managed small teams, and I often found myself being the "translator" between the technical people and the customers.  In fact, on several occasions I acted as translator between different groups within a company.  I developed the knack for hearing what someone "meant" and rephrasing it (and using lots of lame analogies) to get the one group to actually hear and understands the other people's wishes and concerns.

3) Good luck with the iClone Python programming.  It will be fun to see what you manage to produce.





iClone 7... Character Creator... Substance Designer/Painter... Blender... Audacity...
Desktop (homebuilt) - Windows 10, Ryzen 9 3900x CPU, GTX 1080 GPU (8GB), 32GB RAM, Asus X570 Pro motherboard, 2TB SSD, terabytes of disk space, dual  monitors.
Laptop - Windows 10, MSI GS63VR STEALTH-252, 16GB RAM, GTX 1060 (6GB), 256GB SSD and 1TB HDD




Reading This Topic