Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Automating Vi-Suite 0.7 beta5 version Light Simulation with radiance Workflow in blender 4.3.0 on windows 10

34 views
Skip to first unread message

Ernesto Katongo

unread,
Dec 5, 2024, 11:30:48 AM12/5/24
to VI-Suite
Hello Ryan,

I'm working on automating the Vi-Suite light simulation with radiance workflow for a simple sphere scene  with a fine mesh which I created manually. 
sphere scene.png
My goal is to programmatically create and link the required nodes (`LiVi Context`, `LiVi Geometry`, `LiVi Simulation`, and `VI CSV Export`) and then execute their respective operators (`liexport`, `ligexport`, `livicalc`, and `csvexport`) to complete the simulation and export the results in a csv file.

Steps Taken Programmatically:

1. Node Creation and Linking: I've created and linked the nodes programmatically with the following Python function:

```
import bpy
import os
def create_vi_suite_node_structure():
    # Enable the scene in the node
    bpy.context.scene.use_nodes = True

    # Creates node tree
    ng = bpy.data.node_groups.new('simulation', 'ViN')
    print("Node tree 'simulation' created.")

    # VI Location Node
    location_node = ng.nodes.new(type="No_Loc")
    location_node.location = (0, 0)
    location_node.loc = '0'
    location_node.latitude = 48.0
    location_node.longitude = 7.84
    print("Location node created.")

    # LiVi Geometry Node
    geometry_node = ng.nodes.new(type="No_Li_Geo")
    geometry_node.location = (230, 140)
    geometry_node.cpoint = '0'  # Set to '0' for faces or '1' for vertices
    geometry_node.offset = 0.001
    geometry_node.triangulate = True  # Setting 'Triangulate' as checked
    print("Geometry node created with parameters set.")

    # LiVi Context Node
    context_node = ng.nodes.new(type="No_Li_Con")
    context_node.location = (210, -120)
    context_node.contextmenu = 'Basic'  # Set to 'Basic' or 'CBDM'
    context_node.skyprog = '1'  # Set to '0' (Gensky), '1' (Gendaylit), etc.
    context_node.spectrummenu = '1'  # Set to '0' (Visible) or '1' (Full)
    context_node.epsilon = 0.3
    context_node.delta = 0.15
    context_node.gref = 0.0
    context_node.gcol = (0.0, 1.0, 0.0)  # Green color
    context_node.shour = 12.0
    context_node.sdoy = 172
    context_node.animated = True
    context_node.startframe = 0
    context_node.endframe = 6  # Replace with appropriate frame number
    context_node.ehour = 13.00
    context_node.edoy = 172
    context_node.interval = 0.19
    context_node.hdr = False
    print("Context node created with parameters set.")

    # LiVi Simulation Node
    simulation_node = ng.nodes.new(type="No_Li_Sim")
    simulation_node.location = (410, 70)
    simulation_node.simacc = '0'  # Set accuracy level as string, e.g., '0' (Low)
    simulation_node.startframe = 1  # Start frame
    simulation_node.endframe = 1  # End frame
    print("Simulation node created with parameters set.")

    # VI CSV Export Node
    export_node = ng.nodes.new(type="No_CSV")
    export_node.location = (610, 0)
    print("Export node created.")

    # Linking the nodes
    ng.links.new(location_node.outputs[0], context_node.inputs[0])
    ng.links.new(geometry_node.outputs[0], simulation_node.inputs[0])
    ng.links.new(context_node.outputs[0], simulation_node.inputs[1])
    ng.links.new(simulation_node.outputs[0], export_node.inputs[0])
    print("Nodes linked.")

    return ng, context_node, geometry_node, simulation_node, export_node
# Save the project
bpy.ops.wm.save_as_mainfile(filepath=myfilepath, myfilename)
print("Blender project saved.")
```
vi suite nodes are created and linked together successfully as shown in the image below
nodes creation.png

**Where the problem lies**
export function.png
I am attempting to programmatically export the LiVi Geometry node, as shown in the attached image above, using the `bpy.ops.node.ligexport()` function. The goal is to pass the geometry data from this node to the LiVi Simulation node for further simple radiance processing in an automated workflow.

2. Overrides and Operator Execution: To export nodes and run simulations, I used the following override structure, based on community advice and simply here

below summarized code :

```
override = {'node': context_node}
bpy.ops.node.liexport(override, 'EXEC_DEFAULT')  # Context export
override['node'] = geometry_node
bpy.ops.node.ligexport(override, 'EXEC_DEFAULT')  # Geometry export
override['node'] = simulation_node
bpy.ops.node.livicalc(override, 'EXEC_DEFAULT')  # Simulation
override['node'] = export_node
bpy.ops.node.csvexport(override, 'EXEC_DEFAULT')  # CSV Export
```
i refined and adjusted the code for debugging purposes

```
return ng, context_node, geometry_node, simulation_node, export_node

# Create and link the nodes
node_tree, context_node, geometry_node, simulation_node, export_node = create_vi_suite_node_structure()

# Save the project
bpy.ops.wm.save_as_mainfile(filepath=filepath and file name)
print("Info: Saved 'sphere automation.blend'")

# Perform Context Export
override = {'node': context_node}
print(f"Override for Context Export: {override}")
bpy.ops.node.liexport(override, 'EXEC_DEFAULT')
print("Context export completed.")

# Perform Geometry Export
override = {'node': geometry_node}
print(f"Override for Geometry Export: {override}")
bpy.ops.node.ligexport(override, 'EXEC_DEFAULT')
print("Geometry export completed.")

# Perform Simulation
override = {'node': simulation_node}
print(f"Override for Simulation: {override}")
bpy.ops.node.livicalc(override, 'EXEC_DEFAULT')
print("Simulation calculation completed.")

# Export CSV Results
override = {'node': export_node}
print(f"Override for CSV Export: {override}")
bpy.ops.node.csvexport(override, 'EXEC_DEFAULT')
print(f"Results exported to: {export_node.file}")
```
Despite successfully creating the nodes and saving the project, every attempt to run the export and simulation operators fails with the following error `An error occurred: 1-2 args execution context is supported`

I also attempted using `INVOKE_DEFAULT` instead of `EXEC_DEFAULT`, but the same error persists.
error.png
Questions

 1. Why does the `error 1-2 args execution context is supported` occur when using operators such as `bpy.ops.node.liexport`, `bpy.ops.node.ligexport`, `bpy.ops.node.livicalc`, and `bpy.ops.node.csvexport` in the script?

 2. How can this issue be resolved for both `EXEC_DEFAULT` and `INVOKE_DEFAULT` contexts? also, Are there additional parameters required in the override context to make these operators work programmatically?

 3. Where can I find scripting documentation for the Vi-Suite add-on in addition to the available documentation in Git hub?

 4. If anyone has successfully automated the Vi-Suite workflow, could you share insights or examples for your approach?

I am new to blender scripting and any assistance will be highly appreciated.

regards 
Ernesto

VI-Suite

unread,
Dec 5, 2024, 12:20:15 PM12/5/24
to VI-Suite
I've never scripted VI-Suite operations but this conversation may help.
Cheers
Ryan

Reply all
Reply to author
Forward
0 new messages