How to export voxel data using python API?

I wonder how to export voxel data using Python API. Is there anyone who can help me? Thank you!


I normally just get it from the h5 input file if you know where it is (in Acoustics it's under Meshes, then eventually in a dataset called voxels - you can use HDF5View to examine your input file).

Some (untested) code to get you started:

import h5py
import s4l_v1 as s4l

def geth5Dataset(h5f, group_name, dataset_name):
	def find_dataset(name):
		if dataset_name in name:
			return name
	with h5py.File(h5f, 'r') as f:
		k = f[group_name].visit(find_dataset)
		return f[group_name + '/' + k][()]

def getVoxels(h5f):
	return geth5Dataset(h5f, 'Meshes', 'voxels')

sim_idx = 0 # Simulation number
sim = s4l.document.AllSimulations[sim_idx]
file_name = sim.GetInputFileName()

file_path = "c:/file_path/"

vox = getVoxels(file_path + file_name)

@montanaro I've tried it and it worked. Thank you very much!