yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #19756
Re: [Question #680907]: Yade Class not find in a user defined python class
Question #680907 on Yade changed:
https://answers.launchpad.net/yade/+question/680907
gaoxuesong posted a new comment:
Sorry, Jan. I make it confucius. I want to write a class for data post-
process. In my defined class, the Sphere class from yade is used. When i
invoke my class from yade terminal, the error comes.
The code in my defined class yadeDatapost is the following,
import numpy as np
import os
class yadeDataPost:
def __init__(self):
pass
def erase_outbox_sphere(self, box):
for eb in O.bodies:
if isinstance(eb.shape, Sphere):
xi = eb.state.pos[0]
yi = eb.state.pos[1]
zi = eb.state.pos[2]
if (xi<box[0] or xi>box[1] or yi<box[2] or yi>box[3] or zi<box[4] or zi>box[5]):
O.bodies.erase(eb.id)
def __str__(self):
return 'this class is execute successfully'
The code inputting in the yade terminal,
yade
O.load('./svdir/time-3.5')
import sys
sys.path.append('/mnt/hgfs/virpc/backup')
from yadedatapost import yadeDataPost
dp1 = yadeDataPost()
box = [2.5e-3, 3.0e-3, 0e-3, 1.0e-3, 0.9e-3, 1.5e-3]
dp1.erase_outbox_sphere(box)
The following is the errors,
In [8]: dp1 = yadeDataPost()
...:
...: box = [2.5e-3, 3.0e-3, 0e-3, 1.0e-3, 0.9e-3, 1.5e-3]
...:
...: dp1.erase_outbox_sphere(box)
...:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/usr/bin/yade in <module>()
3 box = [2.5e-3, 3.0e-3, 0e-3, 1.0e-3, 0.9e-3, 1.5e-3]
4
----> 5 dp1.erase_outbox_sphere(box)
/mnt/hgfs/virpc/backup/yadedatapost.py in erase_outbox_sphere(self, box)
21 def erase_outbox_sphere(self, box):
22 for eb in O.bodies:
---> 23 if isinstance(eb.shape, Sphere):
24 xi = eb.state.pos[0]
25 yi = eb.state.pos[1]
NameError: global name 'Sphere' is not defined
Much thanks.
--
You received this question notification because your team yade-users is
an answer contact for Yade.