← Back to team overview

yade-users team mailing list archive

Re: [Question #235866]: problem with PyRunner when importing Yade in python

 

Question #235866 on Yade changed:
https://answers.launchpad.net/yade/+question/235866

    Status: Open => Answered

Jan Stránský proposed the following answer:
Hi Alexander,
try to call specific object, like

command="mySim.storeData()"

if this does not work, add

import __builtin__
__builtin__.mySim = mySim

after you create mySim

If nothing of this works, let us know :-)

cheers
Jan



2013/9/17 Alexander Eulitz [Eugen] <question235866@xxxxxxxxxxxxxxxxxxxxx>

> New question #235866 on Yade:
> https://answers.launchpad.net/yade/+question/235866
>
> Hi,
> I imported Yade in python like described in [1].
> This works but when I create a class in which Yade is called and add a
> PyRunner that calls a function of the class, I get an error:
> NameError: name 'self' is not defined
> Traceback (most recent call last):
>   File "<string>", line 1, in <module
>
> Can somebody help me with that, please?
>
> here is the code:
> import sys
> sys.path.append('/home/dummy/Yade/YadePythonImport')
> from yadePythonImport import *
>
> class MyYadeSim():
>     def __init__(self):
>         self.data = []
>         O.engines=[ForceResetter(),
>
>  InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
>                    InteractionLoop(
>
> [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()],
>                           [Ip2_FrictMat_FrictMat_MindlinPhys()],
>                           [Law2_ScGeom_MindlinPhys_Mindlin()]
>                    ),NewtonIntegrator(gravity=(0,0,-9.81),
> label='newtonIntegrator'),
>             PyRunner(iterPeriod=1, command="self.storeData()",
> label='storage')
>                 ]
>     def run(self):
>         O.run(10,True)
>         print self.data
>     def storeData(self):
>         self.data.append(O.time)
> if __name__ == "__main__":
>     mySim = MyYadeSim()
>     mySim.run()
>
> ------
> [1]
> https://yade-dem.org/doc/user.html#importing-yade-in-other-python-applications
>
> --
> You received this question notification because you are a member of
> yade-users, which is an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to     : yade-users@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~yade-users
> More help   : https://help.launchpad.net/ListHelp
>

-- 
You received this question notification because you are a member of
yade-users, which is an answer contact for Yade.