Created
June 13, 2021 17:38
-
-
Save sortofsleepy/6b8ac9f5048fd6d8538cfd9596937e1e to your computer and use it in GitHub Desktop.
Basic way to export props of a geo node in Houdini into Json.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, os | |
# adapted from here with minor tweaks | |
# https://github.com/sideeffects/GameDevelopmentToolset/blob/Development/otls/rop_csv_exporter.hda/gamedev_8_8Driver_1rop__csv__exporter/PythonModule#L43 | |
# needs a bit more work to make it better but works well enough for now. | |
node = hou.pwd() | |
geo = node.geometry() | |
filename = "./tester.json" | |
separator = "," | |
def export(node): | |
# Gather some data from the parameters | |
node_name = "scatter1" | |
csv_path = filename | |
# determines whether or not to write each component separately or | |
# to group components together into a string form | |
# ie for example writing out x,y,z,w vs writing out "(x,y,z,w)" | |
separate_components = True; | |
# not foolproof but helps to append and x,y,z value to attributes like P | |
suffix_x = "x" | |
suffix_y = "y" | |
suffix_z = "z" | |
suffix_w = "w" | |
component_suffixes = [suffix_x, suffix_y, suffix_z, suffix_w] | |
if not os.path.exists(os.path.dirname(csv_path)): | |
os.makedirs(os.path.dirname(csv_path)) | |
ExportAttributes = [x.name() for x in geo.pointAttribs()] | |
with open(csv_path, 'wb') as csvfile: | |
attributes = [] | |
# setup attributes buffer with names of all properties. | |
for point_attr_name in ExportAttributes: | |
point_attr = None | |
if geo.findPointAttrib(point_attr_name) != None: | |
point_attr = geo.findPointAttrib(point_attr_name) | |
attributes.append({ | |
"attrib":point_attr.name(), | |
"data":[] | |
}) | |
# append data to the appropriate attributes | |
for point in geo.points(): | |
# build an array of data for each attribute | |
point_data = [] | |
for point_attr_name in ExportAttributes: | |
point_attr = None | |
if geo.findPointAttrib(point_attr_name) != None: | |
point_attr = geo.findPointAttrib(point_attr_name) | |
for attr in attributes: | |
if point_attr.name() == attr["attrib"]: | |
if separate_components and point_attr.size()>1: | |
for i in range(point_attr.size()): | |
attr["data"].append(point.attribValue(point_attr)[i]) | |
else: | |
attr["data"].append(point.attribValue(point_attr)) | |
json.dump(attributes,csvfile) | |
export(node) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment