2
$\begingroup$

I am just starting to learn python with Blender and I am writing a simple script that loads a list of values from a CSV file and accesses the selected Node which is a Float Curve Node. My question is, how do I take the selected Float Curve Node’s curve and replace it with the list of points from the CSV file? Can I access the Float Curve Node’s Data directly? Any help would be greatly appreciated.

Current Script.

import bpy, csv

fp = "D:\Test.csv"

data=[]
times=[]
locations=[]
with open( fp ) as csvfile:
    rdr = csv.reader( csvfile )
    for i, row in enumerate( rdr ):
        #if i == 0: continue # Skip column titles
        times.append(row[0])
        locations.append(row[1])

for i in range(len(times)):
    row=[float(times[i]),float(locations[i])]
    data.append(row)
    
for row in data:
    print(row)
    
#I have the Data

bpy.context.area.ui_type = 'GeometryNodeTree'
node=bpy.context.selected_nodes
print(node)
# I have the node I want.

#Ok, now what???

bpy.context.area.ui_type = 'TEXT_EDITOR'
$\endgroup$

1 Answer 1

3
$\begingroup$

here's a snippet that worked for me, based on this previous answer
just the data path and the number of curves changes but all the rest is valid

import bpy
m = bpy.data.node_groups['Geometry Nodes'].nodes['Float Curve'].mapping

for i in range(9):
    m.curves[0].points.new(i/10+.1, i/10+.1)
    m.curves[0].points[i].handle_type = 'VECTOR'

for p in m.curves[0].points:
    print (p.location)

m.update()

curves widget

$\endgroup$
1
  • 1
    $\begingroup$ That worked. Thank you. $\endgroup$ Mar 18, 2022 at 14:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .