Home › Forum › SOFA › Using SOFA › How to run a .py file several times?
Tagged: 64_bits, Linux_ubuntu, SOFA_1706
- This topic has 5 replies, 2 voices, and was last updated 6 years ago by ElDiwiny.
-
AuthorPosts
-
15 October 2018 at 18:11 #12218ZahraBlocked
Hi,
I need to run a scene several times while at each run the applied force changes and the resulted mesh should be exported after a specified time steps with different name. I tried to add some loops in the python script but it is not working. Would any one help me regarding this?
The python script is available in the link below:
https://gist.github.com/zbounik/00fd0ecf1c2f3d4c4265b785aff054da
Best,
Zahra
15 October 2018 at 19:51 #12220ElDiwinyBlockedHi Zahra,
Can you attach this file /home/zahra/sofa/Work/testbygmsh/livertetra7509.msh
16 October 2018 at 14:14 #12228ZahraBlockedDear Marwa,
Sorry I forgot to include the mesh files. Below please find the required files:
livertetra7509.msh :
https://gist.github.com/zbounik/1264c9cafe37b83438e854cd44881bd9livertetra181.gmsh:
https://gist.github.com/zbounik/5a5c4105cbe7d98c6120c584bb7b6a13
Best,
Zahra
17 October 2018 at 15:51 #12236ElDiwinyBlockedDear Zahra,
Kindly I am attaching the updated files for your scene in the following link: https://drive.google.com/open?id=1t-4KfJ4Y-c7d8XJlRcdR66Y9YQku4lZJ
As far as I understood from your question that you are looking for changing the value the constant force field applied at a specific time frame or by pressing a certain key.
For doing that: in the attached files, there is a separate
liver_controller.py
, where you can add two different approachesdef onKeyPressed(self,c):
or
def onBeginAnimationStep(self,dt):
which I have added in the attached fileimport Sofa import os from time import gmtime, strftime class controller(Sofa.PythonScriptController): def initGraph(self, node): self.rootNode = node self.Liver= node.getChild('Liver') self.Visu_fine= self.Liver.getChild('Visu-fine') self.coarse = self.Liver.getChild('coarse') self.Visu_coarse= self.coarse.getChild('Visu-coarse') self.mainNode = 2; self.notYetDone=True self.totalTime = 0 def onBeginAnimationStep(self,dt): self.totalTime+=dt forces=self.Liver.getObject('constantFF0').findData('forces').value if (self.totalTime<=0.4): forces=[0,-120,0] self.Liver.getObject('constantFF0').findData('forces').value = forces; if ( 0.7 <self.totalTime<0.71): forces=[0,-50,0] self.Liver.getObject('constantFF0').findData('forces').value = forces; return 0
By checking the constant force field, the value of the force is changing, however, I dont fully understand your scene very well.
Can you check this first and let me know.
Best,
Marwa22 October 2018 at 15:52 #12253ZahraBlockedDear Marwa,
Thank you very much for your reply. This is not what exactly I want to do, but your reply gave me some hints. I tried to check it, however, I have a big problem here: how can I run “liver_controller.py”? Should I add it to the end of my script? It is not working!
Thank you in advance,
Zahra
22 October 2018 at 15:58 #12254ElDiwinyBlockedDear Zahra,
I am so sorry for not understanding what you are looking forward to do in your scene. Concerning your question: you dont need to run liver_controller.py as it is already embedded in liver.py scene as follows:
rootNode.createObject('PythonScriptController', classname="controller", filename="liver_controller.py")
So, all you need to do is go to the directory of this folder (https://drive.google.com/drive/folders/1t-4KfJ4Y-c7d8XJlRcdR66Y9YQku4lZJ) where scene and its controller founded and just run the main scene liver.py
runSofa liver.py
Please let me know whether you need any further help.
-
AuthorPosts
- You must be logged in to reply to this topic.