-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbutils.py
102 lines (92 loc) · 3.28 KB
/
butils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import bpy
from ase import Atom, Atoms
def object_mode():
for object in bpy.data.objects:
if object.mode == 'EDIT':
bpy.ops.object.mode_set(mode = 'OBJECT')
def read_batoms_collection_list():
"""
Read all blase collection
"""
items = [col.name for col in bpy.data.collections if col.is_batoms]
return items
def read_atoms_list(coll):
'''
'''
coll_atom_kinds = [coll for coll in coll.children if 'atoms' in coll.name][0]
elements = []
for obj in coll_atom_kinds.all_objects:
ele = obj.name.split('_')[2]
elements.append(ele)
return elements
def read_atoms_select():
'''
'''
from ase import Atoms, Atom
atoms = Atoms()
cell_vertexs = []
for obj in bpy.context.selected_objects:
if "BOND" in obj.name.upper():
continue
if obj.type not in {'MESH', 'SURFACE', 'META'}:
continue
name = ""
if 'atom_kind_' == obj.name[0:10]:
print(obj.name)
ind = obj.name.index('atom_kind_')
ele = obj.name[ind + 10:].split('_')[0]
if len(obj.children) != 0:
for vertex in obj.data.vertices:
location = obj.matrix_world @ vertex.co
atoms.append(Atom(ele, location))
else:
if not obj.parent:
location = obj.location
atoms.append(Atom(ele, location))
# cell
if 'point_cell' == obj.name[0:10]:
print(obj.name)
if len(obj.children) != 0:
for vertex in obj.data.vertices:
location = obj.matrix_world @ vertex.co
# print(location)
cell_vertexs.append(location)
# print(atoms)
# print(cell_vertexs)
if cell_vertexs:
cell = [cell_vertexs[4], cell_vertexs[2], cell_vertexs[1]]
atoms.cell = cell
atoms.pbc = [True, True, True]
# self.atoms = atoms
return atoms
def remove_collection(name):
collection = bpy.data.collections.get(name)
for obj in collection.all_objects:
bpy.data.objects.remove(obj, do_unlink=True)
for coll in collection.children:
bpy.data.collections.remove(coll)
bpy.data.collections.remove(collection)
def clean_objects():
for item in bpy.data.objects:
bpy.data.objects.remove(item)
def removeAll():
#types = ['MESH', 'CURVE', 'SURFACE', 'META', 'FONT', 'ARMATURE', 'LATTICE', 'EMPTY', 'GPENCIL', 'CAMERA', 'LIGHT', 'SPEAKER', 'LIGHT_PROBE']
for mesh in bpy.data.meshes:
bpy.data.meshes.remove(mesh)
for obj in bpy.data.objects:
bpy.data.objects.remove(obj)
for cam in bpy.data.cameras:
bpy.data.cameras.remove(cam)
for light in bpy.data.lights:
bpy.data.lights.remove(light)
for mat in bpy.data.materials:
bpy.data.materials.remove(mat)
for coll in bpy.data.collections:
if coll.name == 'Collection': continue
bpy.data.collections.remove(coll)
def lock_camera_to_view(switch):
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
for space in area.spaces:
if space.type == 'VIEW_3D':
space.lock_camera = switch