1
$\begingroup$

I'm new to Blender and I'm trying to create a 3d scene starting from a csv file. I explain my problem: I have some 3d objects that I append in the scene with this function:

import bpy

bpy.ops.wm.append(
directory= "C:/Users/Valentina/Desktop/ku/stadium.blend\\Object\\" , 
filepath= "stadium.blend" ,  
filename= "stadium")

stadium is the 3d element that I have to put in the virtual scene. If I create a csv file like this:

name; path
stadium; directory= "C:/Users/Valentina/Desktop/ku/stadium.blend\\Object\\" , filepath= "stadium.blend" , filename= "stadium"

cinema; directory= "C:/Users/Valentina/Desktop/ku/cinema.blend\\Object\\" , filepath= "cinema.blend" , filename= "cinema"

...
...

Will I be able to import the 3d object in the scene by reading the csv file? For example:

import csv
with open ('my_file.csv', 'r') as f:
   r= csv reader(f, delimiter =';')
   for row in r:
       bpy.ops.wm.append(row[1])

Am I totally wrong?

$\endgroup$
1
  • 1
    $\begingroup$ The CSV seems to be broken. Your file looks like it uses semicolon-space as a separator first, and then comma-space. You also use equals-space, making it even harder to parse this file. $\endgroup$
    – dr. Sybren
    Feb 27, 2017 at 12:28

1 Answer 1

1
$\begingroup$

With a text file like this:

test1;E:\yourpath\file1.blend\Object\;Cube
test2;E:\yourpath\file2.blend\Object\;Sphere

Where:

  • First field: a name
  • Second field: the complete path to your object
  • Third field: your object name

You can:

import bpy
import csv

textFile = 'E:\\Blender\\yourpath\\import.txt'

with open( textFile, 'r' ) as file:
    reader = csv.reader( file, delimiter = ';' )
    for row in reader:
        bpy.ops.wm.append( directory=row[1], filename=row[2] )
$\endgroup$
5
  • $\begingroup$ Hi! It doesn't work! :( Do you know the problem? the console says: nothing indicated. I posted an image above. p.s. Is it better a .txt file and not a .csv file? $\endgroup$ Feb 27, 2017 at 10:13
  • $\begingroup$ I have solved my problem! thank you so much!!!:* $\endgroup$ Feb 27, 2017 at 10:18
  • $\begingroup$ The file extension does not matter so much here. But the content of it matters. Could you indicate a link for it or simply past its content in the comments? $\endgroup$
    – lemon
    Feb 27, 2017 at 10:19
  • $\begingroup$ OK... if I understand well it works? A possibility: add a "try except" around the wm.append, because some of the blend files or objects may be not found $\endgroup$
    – lemon
    Feb 27, 2017 at 10:21
  • $\begingroup$ There was a stupid error in the path . :) $\endgroup$ Feb 27, 2017 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.