Update addons for changes to proportional edit mode
[blender-addons.git] / io_mesh_atomic / xyz_export.py
blob79e99736cb9bcd52aa3544cb5e61e5d201fff47c
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 import bpy
20 from io_mesh_atomic.xyz_import import ELEMENTS_DEFAULT
23 class AtomsExport(object):
24 __slots__ = ('element', 'location')
25 def __init__(self, element, location):
26 self.element = element
27 self.location = location
30 def export_xyz(obj_type, filepath_xyz):
32 list_atoms = []
33 counter = 0
34 for obj in bpy.context.selected_objects:
36 if "STICK" in obj.name.upper():
37 continue
39 if obj.type not in {'MESH', 'SURFACE', 'META'}:
40 continue
42 name = ""
43 for element in ELEMENTS_DEFAULT:
44 if element[1] in obj.name:
45 if element[2] == "Vac":
46 name = "X"
47 else:
48 name = element[2]
50 if name == "":
51 if obj_type == "0":
52 name = "?"
53 else:
54 continue
56 if len(obj.children) != 0:
57 for vertex in obj.data.vertices:
58 location = obj.matrix_world @ vertex.co
59 list_atoms.append(AtomsExport(name, location))
60 counter += 1
61 else:
62 if not obj.parent:
63 location = obj.location
64 list_atoms.append(AtomsExport(name, location))
65 counter += 1
67 xyz_file_p = open(filepath_xyz, "w")
68 xyz_file_p.write("%d\n" % counter)
69 xyz_file_p.write("This XYZ file has been created with Blender "
70 "and the addon Atomic Blender - XYZ. "
71 "For more details see the wiki pages of Blender.\n")
73 for i, atom in enumerate(list_atoms):
74 string = "%3s%15.5f%15.5f%15.5f\n" % (
75 atom.element,
76 atom.location[0],
77 atom.location[1],
78 atom.location[2])
79 xyz_file_p.write(string)
81 xyz_file_p.close()
83 return True