Fix #100973: Node Wrangler: Previewing node if hierarchy not active
[blender-addons.git] / io_mesh_atomic / xyz_export.py
blob13fcebb9b4486c0463c7bb6d4e00ed2d911828d6
1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 import bpy
6 from io_mesh_atomic.xyz_import import ELEMENTS_DEFAULT
9 class AtomsExport(object):
10 __slots__ = ('element', 'location')
11 def __init__(self, element, location):
12 self.element = element
13 self.location = location
16 def export_xyz(obj_type, filepath_xyz):
18 list_atoms = []
19 counter = 0
20 for obj in bpy.context.selected_objects:
22 if "STICK" in obj.name.upper():
23 continue
25 if obj.type not in {'MESH', 'SURFACE', 'META'}:
26 continue
28 name = ""
29 for element in ELEMENTS_DEFAULT:
30 if element[1] in obj.name:
31 if element[2] == "Vac":
32 name = "X"
33 else:
34 name = element[2]
36 if name == "":
37 if obj_type == "0":
38 name = "?"
39 else:
40 continue
42 if len(obj.children) != 0:
43 for vertex in obj.data.vertices:
44 location = obj.matrix_world @ vertex.co
45 list_atoms.append(AtomsExport(name, location))
46 counter += 1
47 else:
48 if not obj.parent:
49 location = obj.location
50 list_atoms.append(AtomsExport(name, location))
51 counter += 1
53 xyz_file_p = open(filepath_xyz, "w")
54 xyz_file_p.write("%d\n" % counter)
55 xyz_file_p.write("This XYZ file has been created with Blender "
56 "and the addon Atomic Blender - XYZ. "
57 "For more details see the wiki pages of Blender.\n")
59 for i, atom in enumerate(list_atoms):
60 string = "%3s%15.5f%15.5f%15.5f\n" % (
61 atom.element,
62 atom.location[0],
63 atom.location[1],
64 atom.location[2])
65 xyz_file_p.write(string)
67 xyz_file_p.close()
69 return True