Home › Forum › SOFA › Using SOFA › [SOLVED] no "createScene" nor "createSceneAndController" module method found error
Tagged: 64_bits, Linux_ubuntu, SOFA_1612
- This topic has 10 replies, 3 voices, and was last updated 6 years, 2 months ago by Zahra.
-
AuthorPosts
-
25 July 2018 at 13:18 #11515ZahraBlocked
Hello,
I am trying the “python-scripting” instructions in the documentation. I test the plugin using the fontain example as in “runSofa applications/plugins/SofaPython/examples/fontain.scn” and it works fine. Now I have many questions and I would appreciate your guidance:
1. regarding the “write your python script” section, would you please explain what does the next line mean and what should I do with that(?):
** style=”text-decoration: underline;”>In your scene**
2. In order to translate a scene in a python script, I have followed based on the instructions in the documentation. The .scn file is successfully translated into .py but when I try to use –argv, it says “Unknown option: –argv” and then I receive this error:
[ERROR] [SofaPython] cannot create Scene, no “createScene(rootNode)” nor “createSceneAndController(rootNode)” module method found.For more clarity, I am adding the commands I applied in the terminal in below:
/home/zahra/sofa/Sofa17.06/src/applications/plugins/SofaPython/scn2python.py /home/zahra/PhD/python//testpythonsofa/caduceus.scn Input Scene: /home/zahra/PhD/python//testpythonsofa/caduceus.scn, replace node: None, output: /home/zahra/PhD/python//testpythonsofa/caduceusPython, produce .scn and .py: True zahra@zahra-System-Product-Name:~$ /home/zahra/sofa/Sofa17.06/build/bin/runSofa /home/zahra/PhD/python/testpythonsofa/caduceusPython.py –argv “VariableName” valueNumber valueString Unknown option: –argv [INFO] [SofaPython] Added ‘/home/zahra/sofa/Sofa17.06/src/applications/plugins/SofaPython/python’ to sys.path [INFO] [SofaPython] Added ‘/home/zahra/sofa/Sofa17.06/src/applications/plugins/SofaTest/python’ to sys.path [INFO] [PluginManager] Loaded plugin: /home/zahra/sofa/Sofa17.06/build/lib/libSofaPython.so [ERROR] [SofaPython] cannot create Scene, no “createScene(rootNode)” nor “createSceneAndController(rootNode)” module method found.
Best,
Zahra
25 July 2018 at 17:51 #11519NouraBlockedHi Zahra,
Regarding your first question, that line is not important, it’s just an html foramt error which should underline the phrase “In your scene”.
In your scene, if you want to use Python …For your second question:
First of all try to test your scene without arguments, run:
zahra@zahra-System-Product-Name:~$ /home/zahra/sofa/Sofa17.06/build/bin/runSofa /home/zahra/PhD/python/testpythonsofa/caduceusPython.py
If it works fine, now we come to the next issue: it looks like you are using a wrong character before the argv ‘–’, make sure that it is the minus sign ‘-‘ and you also missed an additional one, try to run:
zahra@zahra-System-Product-Name:~$ /home/zahra/sofa/Sofa17.06/build/bin/runSofa /home/zahra/PhD/python/testpythonsofa/caduceusPython.py --argv “VariableName” valueNumber valueString
this should work fine in case the previous works.
Afterwards, I’m not sure what are you doing with these parameters, if your objective is just to follow the tutorial, so the idea here is that you can pass some variables to your simulation directly when you start your simulation, for example:
runSofa caduceusPython.py --argv “material_stiffness” 5000 rubber
Then you can read these values directly in your python code as explained in the tutorial, For example while you create the scene graph:def createGraph(self,rootNode): variableName = self.commandLineArguments[1] # Get the name of the varible material_stiffness" valueString = self.commandLineArguments[3] # Get the string value "rubber" # rootNode rootNode.createObject('VisualStyle', displayFlags='showVisual ')
So far, you will get “material_stiffness” in the variableName and “rubber” in the valueString. You may then use these variables in the python script.
Hope this helps!
Noura
26 July 2018 at 14:12 #11535HugoKeymasterHi Zahra, Hi Noura,
Noura is correct it was a html/markdown format issue. It is fixed. Thanks for noticing us.
Regarding the script, again Noura is correct.
Why not simply run the script and then runrunSofa caduceusPython.py
This should run fine.Best
Hugo
30 July 2018 at 11:35 #11612ZahraBlockedDear Noura,
Thank you for your guidance. As you mentioned, I am running this:
/home/zahra/sofa/Sofa17.06/build/bin/runSofa /home/zahra/sofa/Sofa17.06/src/examples/Demos/caduceusPython.py
and I am getting this error:
cannot create Scene, no "createScene(rootNode)" nor "createSceneAndController(rootNode)" module method found.
I can not find what is the problem. I appreciate your help.
I tried to copy the caduceusPython.py here, but then your system considers my message as a spam.30 July 2018 at 12:37 #11613ZahraBlockedDear Hugo,
You have mentioned that “simply run the script and then run runSofa caduceusPython.py”, I am so sorry but I am really confused: Which script I should run before ‘runSofa caduceusPython.py’?
31 July 2018 at 17:35 #11616HugoKeymasterHI Zahra,
I was referring to the scn2python script to apply on the caduceus.scn file in order to get the caduceusPython.py
BestHugo
24 September 2018 at 15:29 #11996ZahraBlockedHi,
I am applying scn2python on my scenes and it translates correctly to a python script. But when I try to run it by runSofa, I get this error:
cannot create Scene, no “createScene(rootNode)” nor “createSceneAndController(rootNode)” module method found.
How can I run sofa in debug mode in Ubuntu to see at what line I got this error?
Best,
Zahra
24 September 2018 at 18:14 #11998HugoKeymasterHey @zahra
Could you share with us the generated python file?
What version of SOFA are you using?
Source or binaries?Cheers,
Hugo
25 September 2018 at 18:02 #12019ZahraBlockedHi @Hugo,
– I am using the stable version SOFA 17.06, and this is my generated python file:
https://gist.github.com/zbounik/b0043c19b817db11df45419c77afd645
Best,
Zahra
26 September 2018 at 11:46 #12029HugoKeymasterHi Zahra
Indeed I can reproduce the problem.
Just afterimport Sofa
you can add:def createScene(rootNode): rootNode.createObject('RequiredPlugin', name='SofaPython') mySimulation = Ttest(rootNode,[]) return 0;
and define all your scene in the initGraph function instead of the createGraph function.
Resulting in:
""" TtestPython is based on the scene /home/zahra/sofa/Work/test/Ttest.scn but it uses the SofaPython plugin. Further informations on the usage of the plugin can be found in sofa/applications/plugins/SofaPython/doc/SofaPython.pdf To lance the scene, type runSofa /home/zahra/sofa/Work/test/TtestPython.scn The current file has been written by the python script /home/zahra/sofa/Sofa17.06/src/applications/plugins/SofaPython/scn2python.py Author of scn2python.py: Christoph PAULUS, christoph.paulus@inria.fr """ import Sofa def createScene(rootNode): rootNode.createObject('RequiredPlugin', name='SofaPython') mySimulation = Ttest(rootNode,[]) return 0; class Ttest (Sofa.PythonScriptController): def initGraph(self,rootNode): # rootNode rootNode.createObject('DefaultPipeline', name='CollisionPipeline', verbose='0') rootNode.createObject('BruteForceDetection', name='N2') rootNode.createObject('DefaultContactManager', name='collision response', response='default') rootNode.createObject('DiscreteIntersection', name='discreteIntersection1') # rootNode/Liver Liver = rootNode.createChild('Liver') Liver.depend = 'topo dofs' Liver.createObject('EulerImplicitSolver', name='cg_odesolver', printLog='0') Liver.createObject('CGLinearSolver', threshold='1e-09', tolerance='1e-09', name='linear solver', iterations='25', template='GraphScattered') Liver.createObject('MeshGmshLoader', tetrahedraGroups=' -1 0 38144', name='loader', filename='/home/zahra/sofa/Work/testbygmsh/livertetra7509.msh') Liver.createObject('TetrahedronSetTopologyContainer', triangles='@loader.triangles', position='@loader.position', edges='@loader.edges', name='topo', tetrahedra='@loader.tetras') Liver.createObject('MechanicalObject', force='0 0 0', name='dofs', template='Vec3d', position='@loader.position', velocity='0 0 0', externalForce='0 0 0', restScale='1') Liver.createObject('TetrahedronSetGeometryAlgorithms', drawColorEdges='0.4 1 0.298039 1', showIndicesScale='0.01', name='GeomAlgo', showPointIndices='0', template='Vec3d') Liver.createObject('DiagonalMass', massDensity='1', name='computed using mass density', template='Vec3d') Liver.createObject('TetrahedralCorotationalFEMForceField', poissonRatio='0.3', name='FEM', computeGlobalMatrix='0', method='large', template='Vec3d', youngModulus='12000') Liver.createObject('PlaneForceField', name='planeFF0', template='Vec3d', normal='0 1 0') Liver.createObject('ConstantForceField', indices='111', name='constantFF0', template='Vec3d', forces='0 -120 0') Liver.createObject('FixedConstraint', indices='11 17 16 15 14 4 3 0 45 95 42 40 38 39 53 62 61 60 4 63 59 125 24 20 19 9', drawSize='0', name='fixedConstraint0', template='Vec3d') Liver.createObject('MeshExporter', exportEveryNumberOfSteps='1', quads='0', name='meshExporter3', format='gmsh', exportAtEnd='1', filename='/home/zahra/sofa/Work/Exported/Fine/LiverFine_111_0_-120_0', exportAtBegin='1', hexas='0', edges='0', listening='0', triangles='0') Liver.createObject('TetrahedronSetTopologyModifier', name='tetrahedronSetTopologyModifier9') Liver.createObject('TetrahedronSetTopologyAlgorithms', name='tetrahedronSetTopologyAlgorithms10', template='Vec3d') # rootNode/Liver/Visu-fine Visu_fine = Liver.createChild('Visu-fine') Visu_fine.createObject('OglModel', sfactor='GL_SRC_ALPHA', blendEquation='GL_FUNC_ADD', name='oglModel0', template='ExtVec3f', dfactor='GL_ONE_MINUS_SRC_ALPHA', material='Default Diffuse 1 0.666667 0 0 1 Ambient 1 0.2 0.2 0.2 1 Specular 0 1 1 1 1 Emissive 0 0 0 0 0 Shininess 0 45 ', primitiveType='DEFAULT') Visu_fine.createObject('IdentityMapping', input='@../', name='identityMap1', template='Vec3d,ExtVec3f', output='@./') # rootNode/Liver/coarse coarse = Liver.createChild('coarse') coarse.createObject('MeshGmshLoader', tetrahedraGroups=' -1 0 596', name='meshGmshLoader1', filename='/home/zahra/sofa/Work/testbygmsh/livertetra181.gmsh') coarse.createObject('TetrahedronSetTopologyContainer', triangles='@meshGmshLoader1.triangles', position='@meshGmshLoader1.position', edges='@meshGmshLoader1.edges', name='tetrahedronSetTopologyContainer2', tetrahedra='@meshGmshLoader1.tetras') coarse.createObject('MechanicalObject', force='0 0 0', name='mObject0', template='Vec3d', position='@meshGmshLoader1.position', velocity='0 0 0', externalForce='0 0 0', restScale='1') coarse.createObject('TetrahedronSetTopologyModifier', name='tetrahedronSetTopologyModifier3') coarse.createObject('TetrahedronSetGeometryAlgorithms', drawColorEdges='0.4 1 0.298039 1', recomputeTrianglesOrientation='0', name='tetrahedronSetGeometryAlgorithms0', showPointIndices='1', flipNormals='1', showIndicesScale='0.01', template='Vec3d') coarse.createObject('TetrahedronSetTopologyAlgorithms', name='tetrahedronSetTopologyAlgorithms1', template='Vec3d') coarse.createObject('MeshExporter', exportEveryNumberOfSteps='1', quads='0', name='meshExporter13', format='gmsh', exportAtEnd='1', filename='/home/zahra/sofa/Work/Exported/Coarse/LiverCoarse_111_0_-120_0', exportAtBegin='1', hexas='0', edges='0', listening='0', triangles='0') coarse.createObject('EulerImplicitSolver', name='eulerImplicitSolver0') coarse.createObject('CGLinearSolver', name='cGLinearSolver1', template='GraphScattered') coarse.createObject('DiagonalMass', name='diagonalMass2', template='Vec3d') coarse.createObject('FixedConstraint', indices='0', name='fixedConstraint3', template='Vec3d') coarse.createObject('PlaneForceField', name='planeFF4', template='Vec3d', normal='0 1 0') coarse.createObject('TetrahedralCorotationalFEMForceField', youngModulus='12000', name='tetrahedralCorotationalFEMFF5', poissonRatio='0.3', template='Vec3d') # rootNode/Liver/coarse/Visu-coarse Visu_coarse = coarse.createChild('Visu-coarse') Visu_coarse.createObject('OglModel', sfactor='GL_SRC_ALPHA', name='oglModel1', material='Default Diffuse 1 0 0 1 1 Ambient 1 0 0 0.2 1 Specular 0 0 0 1 1 Emissive 0 0 0 1 1 Shininess 0 45 ', primitiveType='DEFAULT', template='ExtVec3f', translation='0 0 0', dfactor='GL_ONE_MINUS_SRC_ALPHA', blendEquation='GL_FUNC_ADD') Visu_coarse.createObject('IdentityMapping', input='@../', name='identityMap2', template='Vec3d,ExtVec3f', output='@./') return 0; def onKeyPressed(self, c): return 0; def onKeyReleased(self, c): return 0; def onLoaded(self, node): return 0; def onMouseButtonLeft(self, mouseX,mouseY,isPressed): return 0; def onMouseButtonRight(self, mouseX,mouseY,isPressed): return 0; def onMouseButtonMiddle(self, mouseX,mouseY,isPressed): return 0; def onMouseWheel(self, mouseX,mouseY,wheelDelta): return 0; def onGUIEvent(self, strControlID,valueName,strValue): return 0; def onBeginAnimationStep(self, deltaTime): return 0; def onEndAnimationStep(self, deltaTime): return 0; def onScriptEvent(self, senderNode, eventName,data): return 0; def bwdInitGraph(self, node): return 0; def storeResetState(self): return 0; def reset(self): return 0; def cleanup(self): return 0;
Best
Hugo
26 September 2018 at 13:44 #12030 -
AuthorPosts
- You must be logged in to reply to this topic.