glTF: Replace Separate RGB shader node by new Separate Color node
[blender-addons.git] / io_mesh_atomic / xyz_export.py
blobe89c59caf3959115f321c9c14fef0c6d1983177c
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 import bpy
4 from io_mesh_atomic.xyz_import import ELEMENTS_DEFAULT
7 class AtomsExport(object):
8 __slots__ = ('element', 'location')
9 def __init__(self, element, location):
10 self.element = element
11 self.location = location
14 def export_xyz(obj_type, filepath_xyz):
16 list_atoms = []
17 counter = 0
18 for obj in bpy.context.selected_objects:
20 if "STICK" in obj.name.upper():
21 continue
23 if obj.type not in {'MESH', 'SURFACE', 'META'}:
24 continue
26 name = ""
27 for element in ELEMENTS_DEFAULT:
28 if element[1] in obj.name:
29 if element[2] == "Vac":
30 name = "X"
31 else:
32 name = element[2]
34 if name == "":
35 if obj_type == "0":
36 name = "?"
37 else:
38 continue
40 if len(obj.children) != 0:
41 for vertex in obj.data.vertices:
42 location = obj.matrix_world @ vertex.co
43 list_atoms.append(AtomsExport(name, location))
44 counter += 1
45 else:
46 if not obj.parent:
47 location = obj.location
48 list_atoms.append(AtomsExport(name, location))
49 counter += 1
51 xyz_file_p = open(filepath_xyz, "w")
52 xyz_file_p.write("%d\n" % counter)
53 xyz_file_p.write("This XYZ file has been created with Blender "
54 "and the addon Atomic Blender - XYZ. "
55 "For more details see the wiki pages of Blender.\n")
57 for i, atom in enumerate(list_atoms):
58 string = "%3s%15.5f%15.5f%15.5f\n" % (
59 atom.element,
60 atom.location[0],
61 atom.location[1],
62 atom.location[2])
63 xyz_file_p.write(string)
65 xyz_file_p.close()
67 return True