15 October 2018 at 18 h 11 min #12218
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:
Zahra15 October 2018 at 19 h 51 min #12220
Can you attach this file /home/zahra/sofa/Work/testbygmsh/livertetra7509.msh16 October 2018 at 14 h 14 min #12228
Sorry I forgot to include the mesh files. Below please find the required files:
Zahra17 October 2018 at 15 h 51 min #12236
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 approaches
def onBeginAnimationStep(self,dt):which I have added in the attached file
import 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.
Marwa22 October 2018 at 15 h 52 min #12253
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,
Zahra22 October 2018 at 15 h 58 min #12254
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
Please let me know whether you need any further help.
You must be logged in to reply to this topic.