0
$\begingroup$

I'm trying to create an addon that simulates cells with a range of randomized features. The idea is for the user to be able to enter min and max range values in the addon, and the chosen values to be stored in a spreadsheet which is later used to simulate the cell geometry. Right now, I just want to know how to create an excel sheet that stores addon inputs.

I am very new to blender, especially the scripting side of things, so any help is appreciated!

$\endgroup$
3
  • 2
    $\begingroup$ What did you achieve so far with scripting? How about starting here docs.blender.org/manual/en/latest/advanced/scripting/… $\endgroup$
    – taiyo
    Jul 18, 2023 at 17:47
  • 2
    $\begingroup$ Agree with @taiyo As to handling csv files, the first google result for python csv looks like a nice starting point: csv — CSV File Reading and Writing — Python 3.11.4 documentation. Reading and writing a csv isn't about how to use Blender, so we can't really help here. And no matter the subject, if you need help, you gotta start somewhere for us to be able to help more than throwing search links ;) $\endgroup$
    – Lauloque
    Jul 18, 2023 at 17:52
  • 1
    $\begingroup$ Could you define what you mean by "addon inputs"? This is not some standard terminology. $\endgroup$ Jul 18, 2023 at 18:10

1 Answer 1

2
$\begingroup$

You can find add-on templates in the Text Editor's Templates menu:

enter image description here

So that's a basic example of how you can write an add-on. Writing CSV is absolutely the same form an add-on as from any other Python script. There are many ways to do so. You could use pandas(need to install the module for Blender's Python in that case) library to work with your data and then save it to CSV with pandas, you could just use csv module as well:

import csv

with open('csv_file.csv', 'w', encoding='UTF8') as f:
    writer = csv.writer(f)
    writer.writerow(["A", "B", "C", "D", "E", "🍓"])

or since CSV is just a text file you could simply write it the same way as you would write any file with Python

So let's say I want to output all my selected objects to a CSV file C:\temp\a.csv and I want to have their names, types, location, rotation euler and scale:

import bpy
import csv


sel = bpy.context.selected_objects
with open(r'C:\temp\a.csv', 'w', encoding='UTF8', newline='') as f:
    writer = csv.writer(f)
    writer.writerow(["Name", "Type", "Location", "Rotation", "Scale"])
    for o in sel:
        writer.writerow([o.name, o.type, o.location[:], o.rotation_euler[:], o.scale[:]])

And here is the output:

enter image description here

$\endgroup$

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