- 12/09/2019 at 08:29 #16961
I’m trying to read variables from an external python script within a VC-python script.
X = 1
In VC Python Script:
This will print me “1”, but if I change the value of X with a python program outside VC, the VC-script will keep print “1” each time I call “print externalscript.X”. If I restart VC and call “print externalscript.X”, it will print me the new value that was assign from the external python.
Also, even if I delete the “import externalscript” row in VC-Script, and then call “print externalscript.X”, it will keep printing the value of X, till the point I restart VC. (I get the feeling here that the import command saves the stuff temporarely somewhere and this is why I keep getting the old values? Even a new import command will not give me the new value of X though?!)
However, if I assign externalscript.X a new value from the VC python script, and call “print externalscript.X”, it will print me the new that I assigned from the VC-script.
Is there a way to read the variable from a VC- script and keep updating the same variable with another python program, and get the new updated value from the VC-script?
It would really me help alot if there is a way to do it this way.1+12/09/2019 at 08:39 #16979
Not sure why, but I think the external Python code is cached somewhere.
I am using an external library myself but everytime I make a change and want to test it, I have to reload the scene. Would be awesome to have the possibility to reload the Python context while a simulation is opened. I looked up the .NET API but couldn’t find anything regarding that.012/09/2019 at 08:45 #16980
Try to use reload:Python123import externalscriptreload(externalscript)print externalscript.X
-k1+12/09/2019 at 11:07 #16988
Hi, Thanks for the tip keke!
I do get the new value of X in the externalscript with the”reload()” command, as long as I edit the value of X in the externalscript manually.
When I let the python program outside VC update the value of X, I still get the old value of X in VC-python script. 😳
maybe I approach this from the wrong angle. Is there another valid way, where I can read in variable values from an external source, with an update time of about 50ms? Maybe go at it by writing to a .txt-file, and read it back with VC-script? Or use sqlite3 if that might work to share variable values between the external python program and VC-python?012/09/2019 at 12:01 #16990
Maybe you could use socket communication?
I attach couple of test models which demo TCP and UDP socket communications. In both layouts blue robot is the master. There are two box components (client and server) with python scripts. One box reads blue robot’s joint values and sends them with a socket to the other box component. This reads the values and sets them in the white robot so that it follows the blue robot.
Here you have two scripts communicating inside VC model but the other python script could be external and it should work the same.
Attachments:You must be logged in to view attached files.4+13/09/2019 at 11:45 #17020
It works like a charm! So mighty thanks for your help!
//1+22/10/2019 at 08:41 #17948
I implemented a layout in which two robots implement twin motion through udp communication.
However, communication between the two layouts or communication between one VC layout and external python scripts cannot make a communication.
What should I do to achieve it ?009/11/2019 at 02:21 #18439
It is hard to tell what kind of problem you have, send the code you have both in the VC script and the external python script so we can see what might be causing the problem.
You must be logged in to reply to this topic.