← Back to team overview

yade-users team mailing list archive

Re: [Question #665569]: export the sphere in specific position with txt format

 

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

Jan Stránský proposed the following answer:
In the case of a txt format, the approach is very similar:

########################
def exportSelectedSpheres():
   def isOK(b):
      x,y,z = b.state.pos
      return isinstance(b.shape,Sphere) and 0<=x and x<=0.000150 and 0<=y and y<=0.00050 and -0.00003<=z and z<=0.00007
   bodies = filter(isOK, O.bodies)
   def toStr(b):
      x,y,z = b.state.pos
      r = b.shape.radius
      return "{} {} {} {}\n".format(x,y,z,r)
   lines = map(toStr, bodies)
   with open('zdj.txt','w') as f:
      f.writelines(lines)

def exportSelectedSpheres2():
   bodies = []
   for b in O.bodies:
      x,y,z = b.state.pos
      if isinstance(b.shape,Sphere) and 0<=x and x<=0.000150 and 0<=y and y<=0.00050 and -0.00003<=z and z<=0.00007:
         bodies.append(b)
   with open('zdj2.txt','w') as f:
      for b in bodies:
         x,y,z = b.state.pos
         r = b.shape.radius
         f.write("{} {} {} {}\n".format(x,y,z,r))
########################

cheers
Jan

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.