Here is a simple approach using the commands module:
def getParticlePositions(pObject, pId, start, end):
cTime = cmds.currentTime(q=True)
positions = {}
fromStart = True
for f in xrange(start, end+1):
cmds.runup(maxFrame=f, fsf=fromStart)
fromStart = False
try:
pos = cmds.particle(pObject, q=True, id=pId,
attribute='position')
except RuntimeError:
pos = None
positions[f] = pos
cmds.currentTime(cTime)
return positions
p = getParticlePositions('particle1', 2, 10, 15)
with open("points.txt", 'w') as f:
for item in sorted(p.iteritems()):
f.write("%d\t%s\n" % item)
The function does a runup over each frame and then gets the particle
position.
I'm sure you could get a bit more control using the API if needed.
On Sun, May 13, 2012 at 6:17 PM, AJ <[email protected]> wrote:
> Hey,
>
> Lets say I have a particle that is moving base on a field for 10
> frames.
> How can I query its position on each frame and write it in text file?
>
> Many thanks for you help in advance.
>
> --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
>
--
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings:
http://groups.google.com/group/python_inside_maya/subscribe