1
$\begingroup$

Is there anyone know,

(a) how to do an ico sphere of radius=0.5;

(b) how to set the verticles' number and faces' number in an ico sphere;

(c) how to export all vertices' locations in the following format to a .dat file?

! each row has all three vertices' location for a face. x1 y1 z1 x2 y2 z2 x3 y3 z3

....

$\endgroup$

2 Answers 2

0
$\begingroup$

For questions a and b, you can find those options in the left-side menu immediately after adding in the icosphere primitive.

enter image description here

For outputing the vertices of each face into a .dat file, I recommend using this script:

import bpy

obj = bpy.context.scene.objects.active
data = obj.data

output_data = []

for face in data.polygons:
    loc_list = []
    precision = 3
    for index in face.vertices:
        vert = data.vertices[index]
        loc_list.append(" ".join([
            str(round(vert.co.x, precision)),
            str(round(vert.co.y, precision)),
            str(round(vert.co.z, precision))
            ])
        )

    output_data.append(" ".join(loc_list))

filepath = "/home/doakey/Desktop/output.dat"
with open(filepath, 'w') as f:
    f.write("\n".join(output_data))

Just copy the python script into Blender's text editor, select the icosphere, and run the script. Be sure to change the output path of your .dat file in the script.

$\endgroup$
9
  • $\begingroup$ HI Thanks for your reply. May I know if I want to set the sphere's radius is 0.5, how much it is of the size? In the same time, can you please tell me wether the row ' with open(filepath, 'w') as f: ' is correct? it shows Python script failed after running it. $\endgroup$
    – Jimmy
    Commented Apr 11, 2018 at 8:26
  • $\begingroup$ I think the size value is the diameter of the icosphere. As for the filepath line, what are you giving as the filepath? If you're using something like "C:\MyDocuments" remember that a "\" is an escape character in python. So you need to double them for it to work like this: "C:\\MyDocuments\\myfolder\\myfile.dat" $\endgroup$
    – doakey3
    Commented Apr 11, 2018 at 11:05
  • $\begingroup$ Thanks so much!!! It really works very well!!! By the way, the size value is the radius I just confirmed. $\endgroup$
    – Jimmy
    Commented Apr 11, 2018 at 11:09
  • $\begingroup$ May I know how can I set the number has 5 decimal places so that I can make all columns have verticle alignmens. $\endgroup$
    – Jimmy
    Commented Apr 11, 2018 at 11:15
  • $\begingroup$ Where you see the str(round(vert.co.x, precision)), lines, change them to look like this: "%.5f" % vert.co.x, "%.5f" % vert.co.y, "%.5f" % vert.co.z $\endgroup$
    – doakey3
    Commented Apr 11, 2018 at 11:33
0
$\begingroup$

Animation Nodes

You can use Animation Nodes to get such information and write it to a file. First, loop over the polygon indices and get the vertices locations at those indices, then get the individual numbers of the vectors, convert them to text and join them using as space as a separator:

Vertices

Then join the output using a linear break as a separator:

Join

Then you can write the text to a text block using the Text Block Writer Node:

Result

Save the text and you are done.

Python

This script will write the data to the text block test.dat:

import bpy

mesh = bpy.data.objects['Icosphere'].data
data = ""

for poly in mesh.polygons:
    for vert in poly.vertices:
        for c in mesh.vertices[vert].co:
            data += str(c) + " "
    data += "\n"
    
if not "test.dat" in bpy.data.texts:
    bpy.data.texts.new("test.dat")

bpy.data.texts['test.dat'].write(data)
$\endgroup$
2
  • $\begingroup$ Hi Omar, I am sorry to say it's a little difficult to find the Animation Nodes for me as a rookie. Would you please tell me how to do that in the blender programme? I really appreciate it! $\endgroup$
    – Jimmy
    Commented Apr 10, 2018 at 20:03
  • $\begingroup$ @Jimmy Animation Nodes is an addon, you can download it from here. I added another approach using Python scripting. $\endgroup$
    – Omar Emara
    Commented Apr 10, 2018 at 20:18

You must log in to answer this question.

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