0

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!

Blendy9000
  • 13
  • 1

1 Answers1

2

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

Martynas Žiemys
  • 24,274
  • 2
  • 34
  • 77