1
$\begingroup$

The background:

Each single vertex has is its own vertex group (single vertex). Why? I need each vertex to have its own name, the only way to name a vertex in Blender is to give it a vertex group which names it. There are 109 vertices on my model, The names I've given them are numerical (0-108), but as you know they could be named anything such as: Vertex 1 or Vert or nbmrr etc.

Each vertices is named using Vertex Groups

Is it possible to export each vertex location and its given vertex group name in a list format in txt?

Example:

0 - (x0.5 y-2.4 z3.9)

1 - (x5 y7 z1)

2 - (x17 y2 z-1.9)

The true formatting would need to looks like this:

True Formatting I would need (alternatively simple output would suffice

That code is from a program called BeamNG and the format is called jbeam. The

$\endgroup$
  • $\begingroup$ You can do that with a very simple python script, without the need to name each vertex group. Do you want me to elaborate ? $\endgroup$ – thibsert May 15 '18 at 18:18
  • $\begingroup$ Something seems to miss in the description of the problem, regarding to the provided sample : why some vertices are named "nr..." and some are named "n...". Is this important? $\endgroup$ – thibsert May 15 '18 at 18:25
  • $\begingroup$ @thibsert that sounds great, yes what script is this, if you could let me know thanks. The naming shown in that sample is not important, what that did is name vertexes based on there location in the blender world sapce, n is 0 / nr is anything left of 0 (negative) nl is anything right of 0 (positive) based on the x axis. $\endgroup$ – Blender Doc May 15 '18 at 18:38
1
$\begingroup$

Open a text editor, click New Text, paste that into the editor :


import bpy
import bmesh

"""
exports all the vertices of the active object in a text file, formated like that :
["n##",x.xxx,y.yyy,z.zzz],
"""

filename="export.txt"

# api shortcuts
ops = bpy.ops
ctx = bpy.context
opo = bpy.ops.object

opo.mode_set(mode='OBJECT', toggle=False)
activeObj = bpy.context.scene.objects.active

opo.mode_set(mode='EDIT', toggle=False)
sel_mode = ctx.tool_settings.mesh_select_mode
ctx.tool_settings.mesh_select_mode = [True, True, True]
mesh = bmesh.from_edit_mesh(activeObj.data)

filepath = bpy.path.abspath("//"+filename)

f=open(filepath,"w+")

for v in mesh.verts:
    print(v.co.x)
    #rounded to 3 digits:
    f.write("[\"n%d\",%03.3f,%03.3f,%03.3f],\n" % (v.index,v.co.x, v.co.y,v.co.z))
    #not rounded:
    #f.write("[\"n%d\",%f,%f,%f],\n" % (v.index,v.co.x, v.co.y,v.co.z))

f.close()

Select your object then press "Run Script" in the text editor.

The script will create a file named "export.txt", in the .blend directory.

By default the scripts rounds the coordinates to 3 digits, like in your sample. If you want more precise values (not rounded), comment line 31 (add a # character) and uncomment line 33 (delete the # character).

$\endgroup$
  • 1
    $\begingroup$ Ok thankyou! this has worked, but it named each node on its own, is it possible to give a name to each node based on the vertex group name? for example: I name a vertex "Vert4" in a vertex group, can it export that name? Each vertex group is a single vertex and has a unique name, there is no other way to name a vertex in blender except assigning it a vertex group and naming it a unique name. $\endgroup$ – Blender Doc May 20 '18 at 19:12

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.