Hello! I’m trying to write out particle data (pos, scale, ID) to an XML file and have managed to get a single frame of data to write out correctly. However, I can’t seem to sort out how to iterate through each frame in Python and add the particle data per frame into the XML. Below is the python script, any ideas?
node = hou.pwd()
from lxml import etree as ET
geo = node.geometry()
root = ET.Element(“ObjectInstances”)
ET.SubElement(root, frame)
for point in geo.points():
pos = point.position()
scale = hou.Point.attribValue(point, ‘Scale’)
rotation = hou.Point.attribValue(point, ‘Rotation’)
ID = “Particle” + repr(hou.Point.attribValue(point, ‘id’)+1)
PosString = repr(pos) + “, ” + repr(pos) + “, ” + repr(pos)
RotString = repr(rotation)
ScaleString = repr(scale) + “, ” + repr(scale) + “, ” + repr(scale)
ET.SubElement(frame, ID,
Location=PosString,
Rotation=RotString,
Scale=ScaleString)
# Do the export
tree = ET.ElementTree(root)
tree.write(“/users/justinpuda/desktop/test4.xml”, pretty_print=True)
Writing sequence of particle data to XML w/ Python + Element Tree
3833 2 1-
- jpuda
- Member
- 4 posts
- Joined: Aug. 2011
- Offline
-
- Enivob
- Member
- 2658 posts
- Joined: June 2008
- Offline
I can’t seem to sort out how to iterate through each frameCheck out hou.setFrame. Also you can fetch the playback range from hou.playbar. Then you can set up an inner loop that matches the playbar range.
http://www.sidefx.com/docs/houdini/hom/hou/setFrame [sidefx.com]
Edited by Enivob - April 19, 2017 12:47:04
Using Houdini Indie 20.5
Windows 11 64GB Ryzen 16 core.
nVidia 3060RTX 12BG RAM.
Windows 11 64GB Ryzen 16 core.
nVidia 3060RTX 12BG RAM.
-
- jpuda
- Member
- 4 posts
- Joined: Aug. 2011
- Offline
Thanks Enviob! I had found setFrame but due to my limited Python experience, I’m having a bit of trouble on the inner loop portion. Would I need to define the amount of frames from the hou.playbar call as a variable and then run a for/while loop? Or does Python have a way to do this with an if/else loop? I’m a bit more familiar with if/else loops than for/while loops from VEX scripting.
-
- Quick Links

