O.bodies.shape ?!

Asked by Christian Jakob

Hello,

I am facing some troubles with a function:

def get_z_o_and_z_u():
 rad_sum = 0.0
 he_real = 0.0
 for ii in sphID:
  rad_sum = rad_sum + O.bodies[ii].shape.radius
  bh = O.bodies[ii].state.pos[2]
  if bh > he_real:
   he_real = bh
   he_eff = he_real + O.bodies[ii].shape.radius

 r_d = rad_sum/sum_spheres
 # determine clump dimensions:
 z_o = he_eff
 z_u = z_o-6*r_d

where sphID is the list of all sphere IDs.

Error message:
  File "/home/me/YADE/YADE2989/bin/yade-bzr2989", line 183, in runScript execfile(script,globals())
  File "4-simulate-depth.py", line 11, in <module> get_z_o_and_z_u()
  File "userinput.py", line 134, in get_z_o_and_z_u
    rad_sum = rad_sum + O.bodies[ii].shape.radius
AttributeError: 'NoneType' object has no attribute 'shape'

I am wondering, because this function works (no Error message):

def updSph(rad=1.0):
 i = 0
 for ii in sphID:
  tempID = O.bodies.append(utils.sphere([O.bodies[ii].state.pos[0],O.bodies[ii].state.pos[1],O.bodies[ii].state.pos[2]], material=O.bodies[ii].material.id, radius=O.bodies[ii].shape.radius*rad, wire=False, highlight=False))
  sphID[i] = tempID
  O.bodies.erase(ii)
  i+=1

Does anyone know why this happens?

Thanks,

Christian

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Anton Gladky
Solved:
Last query:
Last reply:
Revision history for this message
Best Anton Gladky (gladky-anton) said :
#1

Hi,
I think, your list sphID contains some indexes of non-nonexistent bodies.
Try so:

for ii in sphID:
  i = O.bodies[ii]
  if ((i) and (isinstance(i.shape,Sphere))):
    print "We have found a sphere"

Anton

Revision history for this message
Christian Jakob (jakob-ifgt) said :
#2

Thanks Anton Gladky, that solved my question.