VI-Suite v0.3 – Exporting LiVi Data

A user asked me how to export the x, y, z co-ordinates of the LiVi sensor positions with the results to a comma separated file for further plotting or analysis. This capability will be enabled in version 0.4 with the “Results out” socket of the LiVi simulation node, but for now you can copy the python code below into Blender’s text editor and press the “Run Script” button at the bottom of the text editor window. This code will export the currently visualised results for the current frame to files in the project directory. These files are named ‘name_of_results_object.manualres’.

LiVi results data is stored within the mesh’s vertices and faces. To do this LiVi uses Blender’s Bmesh wrapper for the mesh data. So the first part of the code loops through results objects (line 3) creates a bmesh representation of each one (line 5) and transforms the bmesh (line 6) so that vertex and space positions are in global or world co-ordinates.

Line 7 designates either vertices or faces as the results points depending on the object ‘cpoint’ property (which is created on LiVi geometry export). Line 8 then checks that there are results available in the mesh and line 9 defines the cindex layer which stores whether a point in a mesh is a results point. Line 10 defines the resl layer which actually holds the results.

Line 11 generates the vertex or face positions for each results point and stores them in the variable posis. Line 12 and 13 then define the output file and writes the co-ordinates and the data to the file. The final line 14 clears the bmesh data from memory.

import bpy, bmesh, os
scene = bpy.context.scene
for o in [o for o in bpy.data.objects if o.type == 'MESH' and o.get('cpoint') and o.lires]:
    bm = bmesh.new()
    bm.from_mesh(o.data)
    bm.transform(o.matrix_world)
    geom = bm.verts if o['cpoint'] == '1' else bm.faces
    if geom.layers.float.get('res{}'.format(scene.frame_current)) and geom.layers.int.get('cindex'):
        cindex = geom.layers.int['cindex']
        resl = geom.layers.float['res{}'.format(scene.frame_current)]
        posis = [v.co for v in bm.verts if v[cindex] > 0] if o['cpoint'] == '1' else [f.calc_center_bounds() for f in bm.faces if f[cindex] > 0]
        with open(os.path.join(scene['viparams']['newdir'], '{}.manualres'.format(o.name)), 'w') as resfile:
            resfile.write('\n'.join(['{0[0]}, {0[1]}, {0[2]}, {1}'.format(posis[gi], g[resl]) for gi, g in enumerate(geom) if g[cindex] > 0]))
    bm.free()

Indentation in Python is important so make sure the code in the Blender Text editor window looks like the screenshot below.

manualres

2 thoughts on “VI-Suite v0.3 – Exporting LiVi Data

  1. Hi Paul,

    I’m completely unfamiliar with Blender but ok with Radiance, so I apologise in advance if these would be answered by better knowledge of Blender.

    1. Is it possible to name objects in the model such as window planes, calculate the illuminance or VSC on these or for a reference point on it and export the values to a CSV?

    2. Can the object, ie window or analysis grid store more than one piece of data per node, ie in the before and after condition in a comparative analysis scenario?

    3. Is it possible in the Radiance Export node to define the specific input to radiance ie – say the -ab -aa -av values for rtrace?

    Many thanks in advance – it looks very very interesting…

    regards

    Nick

    • Hi Nick.
      I am trying to keep the Google Group as the place where I deal with all support requests. Can you post your question on there and I’ll do my best to answer.
      Ryan

Leave a Reply

Your email address will not be published. Required fields are marked *