-5

How can I create a lot of spheres? I have a csv file with x,y,z,r (radius) coordinates. I saw some topics but nothing worked to me.

I tried ask a question, but this was classified as "Your post has been associated with a similar question. If this question doesn’t resolve your question, ask a new one." I read some topics but nothing worked to me, so that I opened a new topic.

I have this code:

import bpy

text_file = open("C:\Users\nabuc\Desktop\1700txt - copia.txt", "r") lines = []

#Read in contents to a list for line in text_file: lines.append(line.strip())

#create spheres for e in lines: temp=e.split(',') bpy.ops.mesh.primitive_uv_sphere_add(segments = 64, ring_count = 32, location=(float(temp[0]),float(temp[1]),float(temp[2])),size = float(temp[3])) bpy.ops.object.shade_smooth() text_file.close()

but:

Python: File "C:\Users\nabuc\Documents\untitled.blend\Text", line 12 temp=e.split(',') ^ IndentationError: expected an indented block

location: :-1

thanks for your help

EDIT 2 (I can't edit code on answer) To avoid this indentation error, I edit as:

import bpy

text_file = open("C:\Users\nabuc\Desktop\1700txt - copia.txt", "r") lines = []

#Read in contents to a list for line in text_file: lines.append(line.strip())

#create spheres for e in lines: temp=e.split(',') bpy.ops.mesh.primitive_uv_sphere_add(segments = 64, ring_count = 32, location=(float(temp[0]),float(temp[1]),float(temp[2])),size = float(temp[3])) bpy.ops.object.shade_smooth() text_file.close()

but this return:

Python script failed, check the message in the system console

  • looks like you are a pretty beginner ;) you should have written that. First...python needs the right indentation to work. This is what the error says. Since you didn't even format your code right here, we cannot say what's wrong because you just copied/paste your code here without thinking. To make your question to something we can work with you have to do: copy your code in the question, then select the code and then tap this button (brackets)[1]: https://i.stack.imgur.com/JomVW.png so that your code gets formatted. But maybe you should think about posting your blend file... – Chris May 20 '21 at 14:49
  • @Andre welcome to BSE. We like to help. However it is outside the scope of the site to teach python to, or help each individual fix their basic python syntax or runtime errors. Suggest looking into getting a text editor that highlights python syntax errors (like basic indent as above) Search using the error message online eg "IndentationError: expected an indented block" To view a specific error https://blender.stackexchange.com/questions/6173/where-does-console-output-go – batFINGER May 20 '21 at 15:34

1 Answers1

0

i recommend you watching some python basic tutorials. Indentation is an essential part of the python language. And if you don't understand what it does, you will never understand python code.

try this:

import bpy

text_file = open("C:\Users\nabuc\Desktop\1700txt - copia.txt", "r") lines = []

#Read in contents to a list for line in text_file: lines.append(line.strip())

#create spheres for e in lines: temp=e.split(',') bpy.ops.mesh.primitive_uv_sphere_add(segments = 64, ring_count = 32, location=(float(temp[0]),float(temp[1]),float(temp[2])),scale = (float(temp[3]),float(temp[3]),float(temp[3]))) bpy.ops.object.shade_smooth() text_file.close()

Chris
  • 59,454
  • 6
  • 30
  • 84
  • The same error appears (I remove that 'tab' before last line) "Python script failed, check the message in the system console" – Andre Luiz Moura May 20 '21 at 15:22
  • ok, then copy some lines of your .txt here – Chris May 20 '21 at 15:25
  • 3.6105752578067E-4,4.57866439980116E-5,2.96020503639462E-4,3.8E-5 1.29135076069346E-4,1.70596056159248E-4,1.65624196671979E-4,3.8E-5 3.30313121806365E-4,1.01079824554117E-4,1.91925777727024E-4,3.8E-5 2.51591805391055E-4,1.11234635850882E-4,3.09032838060921E-4,3.8E-5 9.60652657019447E-5,8.72360800639832E-5,1.52661649244708E-4,3.8E-5 1.59171641186626E-4,2.9455844644739E-5,1.89453981357743E-5,3.8E-5 2.29775668450222E-4,4.72599828082211E-5,1.40603740903784E-4,3.8E-5 1.70195058529528E-4,1.8789687568838E-4,9.87256408236967E-5,3.8E-5 – Andre Luiz Moura May 20 '21 at 15:29
  • i updated my answer – Chris May 20 '21 at 15:31
  • 1
    Oh my god This worked well!! But the dimension is very little!! (microns) Probably you save my life with my College work (This is just a start point). Now I'm try to see the geometry and export it. Thank you so much – Andre Luiz Moura May 20 '21 at 15:47
  • you are welcome. please check the checkmark left to my answer. thank you. – Chris May 20 '21 at 16:00
  • Do you know, why it create 2 big spheres? – Andre Luiz Moura May 20 '21 at 18:39
  • ooops, sorry, forgot to delete this: lines = ["1,2,3,2","1,2,4,3"] ...this was for my testing. i updated my answer – Chris May 20 '21 at 18:52
  • I thought it was this line that was making the code work hahahaha thank you very much again And go back to studying programming, I studied C ++ a long time ago in a basic way, now I'm going to start python – Andre Luiz Moura May 20 '21 at 19:38
  • Can you please check the checkmark left to my answer? Thanks. – Chris May 20 '21 at 19:39
  • Yes, I'm tried. But: "Thanks for the feedback! You need at least 15 reputation to cast a vote, but your feedback has been recorded." – Andre Luiz Moura May 20 '21 at 19:55
  • The checkmark! Not the upvote! – Chris May 20 '21 at 19:55
  • How do you display the image once this has been done? – GRquanti Jun 21 '23 at 09:06