-
Notifications
You must be signed in to change notification settings - Fork 3
/
easybpy.py
3690 lines (2987 loc) · 107 KB
/
easybpy.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#region INFO
'''
== EasyBPY 0.1.4 ==
Managed by Curtis Holt
https://curtisholt.online/links
---
This purpose of this module is to simplify the use of the Blender API
(bpy) by creating an extra layer of abstraction that is more human-
readable, memorizable and reduces the user's exposure to complex code
paths.
EasyBPY can be added to Blender by installing it into the:
../scripts/modules
folder in the user preferences. The file can also be re-packaged with
any other addon, so long as the developer respects the limitations of
the GPL license, outlined below.
'''
'''
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
#endregion
#region IMPORTS
import re
import bpy
import bpy.types
from mathutils import Vector, Matrix, Euler
import math
import random
from math import radians
#endregion
#region RENDER SETTINGS
def set_render_engine_to_cycles():
get_scene().render.engine = 'CYCLES'
def set_render_engine_cycles():
set_render_engine_to_cycles()
def set_render_engine_to_eevee():
get_scene().render.engine = 'BLENDER_EEVEE'
def set_render_engine_eevee():
set_render_engine_to_eevee()
def render_image(use_view = False):
bpy.ops.render.render(use_viewport=use_view)
return bpy.data.images['Render Result']
def render_animation(use_view = False):
bpy.ops.render.render(animation=True, use_viewport=use_view)
def set_render_resolution(x, y):
get_scene().render.resolution_x = x
get_scene().render.resolution_y = y
def get_render_resolution():
reslist = []
reslist.append(get_scene().render.resolution_x)
reslist.append(get_scene().render.resolution_y)
return reslist
def render_resolution(x = None, y = None):
if x is not None and y is not None:
set_render_resolution(x,y)
else:
return get_render_resolution()
def set_render_resolution_percentage(percent):
get_scene().render.resolution_percentage = percent
def set_render_percentage(percent = None):
set_render_resolution_percentage(percent)
def set_render_percent(percent = None):
set_render_resolution_percentage(percent)
def get_render_resolution_percentage():
return get_scene().render.resolution_percentage
def render_resolution_percentage(percent = None):
if percent is not None:
set_render_resolution_percentage(percent)
else:
return get_render_resolution_percentage()
def set_render_pixel_aspect_ratio(x, y):
get_scene().render.pixel_aspect_x = x
get_scene().render.pixel_aspect_y = y
def get_render_pixel_aspect_ratio():
aspectlist = []
aspectlist.append(get_scene().render.pixel_aspect_x)
aspectlist.append(get_scene().render.pixel_aspect_y)
return aspectlist
def render_aspect_ratio(x = None, y = None):
if x is not None and y is not None:
set_render_pixel_aspect_ratio(x,y)
else:
return get_render_pixel_aspect_ratio()
def current_frame(val = None):
if val is None:
return get_scene().frame_current
else:
get_scene().frame_current = val
def set_frame(val = None):
current_frame(val)
def frame_start(val = None):
if val is None:
return get_scene().frame_start
else:
get_scene().frame_start = val
def frame_end(val = None):
if val is None:
return get_scene().frame_end
else:
get_scene().frame_end = val
def set_current_frame(val = None):
current_frame(val)
def set_frame_start(val = None):
frame_start(val)
def set_frame_end(val = None):
frame_end(val)
def set_start_frame(val = None):
frame_start(val)
def set_end_frame(val = None):
frame_end(val)
def set_frame_interval(start = None, end = None):
frame_start(start)
frame_end(end)
def set_frame_step(val):
get_scene().frame_step = val
def set_render_fps(val, base = 1.0):
get_scene().render.fps = val
get_scene().render.fps_base = base
#endregion
#region APPENDING / LINKING
def append(file, category, object):
if '\\' in file:
#fpath = file.replace('\\', '/') => Not viable for numeric folders.
print("Please use forward slashes in path string.")
else:
if isinstance(object, list) is False:
object = [object]
for o in object:
filepath = file + "\\" + category + "\\" + o
directory = file + "\\" + category + "\\"
filename = o
bpy.ops.wm.append(filepath = filepath, directory = directory, filename = filename)
def append_brush(file, name):
append(file, "Brush", name)
def append_collection(file, name):
append(file, "Collection", name)
def append_freestyle_line_style(file, name):
append(file, "FreestyleLineStyle", name)
def append_image(file, name):
append(file, "Image", name)
def append_material(file, name):
append(file, "Material", name)
def append_mesh(file, name):
append(file, "Mesh", name)
def append_node_tree(file, name):
append(file, "NodeTree", name)
def append_object(file, name):
append(file, "Object", name)
def append_scene(file, name):
append(file, "Scene", name)
def append_text(file, name):
append(file, "Text", name)
def append_texture(file, name):
append(file, "Texture", name)
def append_workspace(file, name):
append(file, "Workspace", name)
def append_world(file, name):
append(file, "World", name)
def link(file, category, object):
if '\\' in file:
#fpath = file.replace('\\', '/') => Not viable for numeric folders.
print("Please use forward slashes in path string.")
else:
if isinstance(object, list) is False:
object = [object]
for o in object:
filepath = file + "\\" + category + "\\" + o
directory = file + "\\" + category + "\\"
filename = o
bpy.ops.wm.link(filepath = filepath, directory = directory, filename = filename)
def link_brush(file, name):
link(file, "Brush", name)
def link_collection(file, name):
link(file, "Collection", name)
def link_freestyle_line_style(file, name):
link(file, "FreestyleLineStyle", name)
def link_image(file, name):
link(file, "Image", name)
def link_material(file, name):
link(file, "Material", name)
def link_mesh(file, name):
link(file, "Mesh", name)
def link_node_tree(file, name):
link(file, "NodeTree", name)
def link_object(file, name):
link(file, "Object", name)
def link_scene(file, name):
link(file, "Scene", name)
def link_text(file, name):
link(file, "Text", name)
def link_texture(file, name):
link(file, "Texture", name)
def link_workspace(file, name):
link(file, "Workspace", name)
def link_world(file, name):
link(file, "World", name)
#endregion
#region OBJECTS
def create_object(name = None, col = None):
if name is None:
name = "New Object"
m = bpy.data.meshes.new(name)
o = bpy.data.objects.new(name, m)
col_ref = None
# Assess col
if col == None:
col_ref=bpy.context.view_layer.active_layer_collection.collection
elif is_string(col):
if col in bpy.data.collections:
col_ref = bpy.data.collections[col]
else:
col_ref = create_collection(col)
else:
col_ref = col
col_ref.objects.link(o)
return o
def copy_object(tocopy, col = None):
# Set up vars
new_obj = None
to_copy = get_object(tocopy)
col_ref = None
# Assess col
if col == None:
col_ref = get_active_collection()
elif is_string(col):
if collection_exists(col):
col_ref = get_collection(col)
else:
col_ref = create_collection(col)
else:
col_ref = col
# Perform action
new_obj = to_copy.copy()
if new_obj.data is not None:
new_obj.data = to_copy.data.copy()
new_obj.animation_data_clear()
col_ref.objects.link(new_obj)
return new_obj
def get_active_object():
return bpy.context.active_object
def set_active_object(ref=None):
objref = get_object(ref)
bpy.context.view_layer.objects.active = objref
def clear_active_object():
bpy.context.view_layer.objects.active = None
def active_object():
return get_active_object()
def get_selected_object():
return get_active_object()
def selected_object():
return get_selected_object()
def ao():
return get_active_object()
def so():
return get_selected_objects()
def get_selected_objects():
return bpy.context.selected_objects
def get_all_objects():
return bpy.data.objects
def get_list_of_objects():
get_all_objects()
def select_object(ref, make_active=True):
objref = get_object(ref)
objref.select_set(True)
if make_active:
bpy.context.view_layer.objects.active = objref
def select_objects(ref):
objref = get_objects(ref)
for o in objref:
o.select_set(True)
def selected_objects():
return get_selected_objects()
def select_all_objects(col = None):
if col == None:
for co in bpy.context.scene.objects:
co.select_set(True)
else:
col_ref = None
if is_string(col):
if collection_exists(col):
col_ref = get_collection(col)
else:
col_ref = col
for c in col_ref.objects:
c.select_set(True)
def select_only(ref = None):
objref = get_object(ref)
deselect_all_objects()
select_object(objref, True)
def deselect_object(ref):
objref = get_object(ref)
objref.select_set(False)
def deselect_all_objects():
for ob in so():
ob.select_set(False)
def delete_selected_objects():
bpy.ops.object.delete()
def delete_object(ref = None):
objref = get_object(ref)
bpy.data.objects.remove(objref, do_unlink=True)
def delete_objects(objlist = None):
objlist = get_objects()
for obj in objlist:
ref = get_object(obj)
bpy.data.objects.remove(ref, do_unlink=True)
def duplicate_object(tocopy,col):
return copy_object(tocopy,col)
def instance_object(ref, newname = None, col = None):
deselect_all_objects()
select_object(ref)
bpy.ops.object.duplicate_move_linked()
o = selected_object()
if newname is not None:
o.name = newname
if col is not None:
link_object_to_collection(o,col)
return o
def get_object(ref):
objref = None
if ref is None:
objref = ao()
else:
if is_string(ref):
if object_exists(ref):
objref = bpy.data.objects[ref]
else:
objref = ref
return objref
def get_obj(ref):
return get_object(ref)
def get_objects(ref = None):
objref = []
if ref is None:
objref = so()
else:
if isinstance(ref, list):
if len(ref) > 0:
if isinstance(ref[0], bpy.types.Object):
objref = ref
elif isinstance(ref[0], str):
for ob_name in ref:
if object_exists(ob_name):
objref.append(bpy.data.objects[ob_name])
elif is_string(ref):
if object_exists(ref):
objref.append(bpy.data.objects[ref])
elif isinstance(ref, bpy.types.Object) :
objref.append(ref)
return objref
def get_objs(ref = None):
return get_objects(ref)
def get_median_point_of_objects(objs):
point_loc = Vector()
for obj in objs:
point_loc += obj.location
point_loc /= len(objs)
return point_loc
def object_exists(ref):
if is_string(ref):
if ref in bpy.data.objects:
return True
else:
return False
# redundant but for safety
else:
if ref.name in bpy.data.objects:
return True
else:
return False
def rename_object(obj, newname):
objref = None
# obj is string
if is_string(obj):
objref = get_object(obj)
else:
objref = obj
# set name - only if string
if is_string(newname):
objref.name = newname
return True
else:
return False
def get_parent(ref = None):
return get_object(ref).parent
def get_children(ref = None):
return get_object(ref).children
def set_parent(child = None,parent = None):
child = get_object(child)
parent = get_object(parent)
child.parent = parent
child.matrix_parent_inverse = parent.matrix_world.inverted()
def clear_parent(ref = None, keep_location = True):
ref = get_object(ref)
loc = ref.matrix_world.to_translation()
print(loc)
ref.parent = None
if keep_location:
ref.location = loc
def get_bounding_box(ref = None):
return get_object(ref).bound_box
def get_bounding_box_corners(ref = None):
return [ref.matrix_world @ Vector(corner) for corner in get_bounding_box(ref)]
#endregion
#region OBJECTS - CONVERSION
def convert_to_mesh(ref):
objref = get_object(ref)
deselect_all_objects()
select_object(objref)
bpy.ops.object.convert(target='MESH')
def convert_to_grease_pencil(ref):
objref = get_object(ref)
deselect_all_objects()
select_object(objref)
bpy.ops.object.convert(target='GPENCIL')
def convert_to_curve(ref):
objref = get_object(ref)
deselect_all_objects()
select_object(objref)
bpy.ops.object.convert(target='CURVE')
#endregion
#region OBJECTS - SELECTION
def select_all_meshes():
bpy.ops.object.select_by_type(type='MESH')
def select_all_curves():
bpy.ops.object.select_by_type(type='CURVE')
def select_all_surfaces():
bpy.ops.object.select_by_type(type='SURFACE')
def select_all_metas():
bpy.ops.object.select_by_type(type='META')
def select_all_text():
bpy.ops.object.select_by_type(type='FONT')
def select_all_hair():
bpy.ops.object.select_by_type(type='HAIR')
def select_all_point_clouds():
bpy.ops.object.select_by_type(type='POINTCLOUD')
def select_all_volumes():
bpy.ops.object.select_by_type(type='VOLUME')
def select_all_armatures():
bpy.ops.object.select_by_type(type='ARMATURE')
def select_all_lattices():
bpy.ops.object.select_by_type(type='LATTICE')
def select_all_empties():
bpy.ops.object.select_by_type(type='EMPTY')
def select_all_grease_pencils():
bpy.ops.object.select_by_type(type='GPENCIL')
def select_all_cameras():
bpy.ops.object.select_by_type(type='CAMERA')
def select_all_lights():
bpy.ops.object.select_by_type(type='LIGHT')
def select_all_speakers():
bpy.ops.object.select_by_type(type='SPEAKER')
def select_all_light_probes():
bpy.ops.object.select_by_type(type='LIGHT_PROBE')
def invert_selection():
bpy.ops.object.select_all(action='INVERT')
def get_objects_with_modifiers():
objlist = []
for obj in bpy.data.objects:
if len(obj.modifiers) > 0:
objlist.append(obj)
return objlist
def select_objects_with_modifiers():
deselect_all_objects()
for obj in bpy.data.objects:
if len(obj.modifiers) > 0:
select_object(obj)
# Custom Selection
def get_objects_including(include, case_sensitive = True):
objlist = []
for o in bpy.context.view_layer.objects: #bpy.data.objects
if case_sensitive is True:
if include in o.name:
objlist.append(o)
else:
if (include.lower() in o.name) or (include.upper() in o.name) or (include in o.name):
objlist.append(o)
return objlist
def select_objects_including(include, case_sensitive = True):
for o in bpy.context.view_layer.objects: #bpy.data.objects
if case_sensitive is True:
if include in o.name:
o.select_set(True)
else:
if (include.lower() in o.name) or (include.upper() in o.name) or (include in o.name):
o.select_set(True)
def get_objects_by_vertex(count = 0, mode="EQUAL"):
cmode = mode.upper()
objlist = []
for o in bpy.data.objects:
if isinstance(o.data, bpy.types.Mesh):
# o.data / len(o.data.vertices)
if cmode == "EQUAL" or cmode == "SAME":
if len(o.data.vertices) == count:
objlist.append(o)
if cmode == "GREATER" or cmode == "MORE":
if len(o.data.vertices) > count:
objlist.append(o)
if cmode == "LESS" or cmode == "FEWER":
if len(o.data.vertices) < count:
objlist.append(o)
return objlist
def select_objects_by_vertex(count = 0, mode="EQUAL"):
objs = get_objects_by_vertex(count, mode)
for o in objs:
o.select_set(True)
#endregion
#region OBJECTS - PRIMITIVES
# Mesh
def create_plane():
bpy.ops.mesh.primitive_plane_add()
return active_object()
def create_cube():
bpy.ops.mesh.primitive_cube_add()
return active_object()
def create_circle():
bpy.ops.mesh.primitive_circle_add()
return active_object()
def create_cylinder():
bpy.ops.mesh.primitive_cylinder_add()
return active_object()
def create_uv_sphere():
bpy.ops.mesh.primitive_uv_sphere_add()
return active_object()
def create_sphere():
return create_uv_sphere()
def create_ico_sphere():
bpy.ops.mesh.primitive_ico_sphere_add()
return active_object()
def create_cone():
bpy.ops.mesh.primitive_cone_add()
return active_object()
def create_torus():
bpy.ops.mesh.primitive_torus_add()
return active_object()
def create_grid():
bpy.ops.mesh.primitive_grid_add()
return active_object()
def create_suzanne():
bpy.ops.mesh.primitive_monkey_add()
return active_object()
def create_monkey():
return create_suzanne()
# Curve
def create_bezier_curve():
bpy.ops.curve.primitive_bezier_curve_add()
return active_object()
def create_bezier():
return create_bezier_curve()
def create_circle_curve():
bpy.ops.curve.primitive_bezier_circle_add()
return active_object()
def create_nurbs_curve():
bpy.ops.curve.primitive_nurbs_curve_add()
return active_object()
def create_nurbs_circle():
bpy.ops.curve.primitive_nurbs_circle_add()
return active_object()
def create_nurbs_path():
bpy.ops.curve.primitive_nurbs_path_add()
return active_object()
def create_path():
return create_nurbs_path()
# Surface
def create_nurbs_curve_surface():
bpy.ops.surface.primitive_nurbs_surface_curve_add()
return active_object()
def create_curve_surface():
return create_nurbs_curve_surface()
def create_nurbs_circle_surface():
bpy.ops.surface.primitive_nurbs_surface_circle_add()
return active_object()
def create_circle_surface():
return create_nurbs_circle_surface()
def create_nurbs_surface():
bpy.ops.surface.primitive_nurbs_surface_surface_add()
return active_object()
def create_nurbs_cylinder_surface():
bpy.ops.surface.primitive_nurbs_surface_cylinder_add()
return active_object()
def create_cylinder_surface():
return create_nurbs_cylinder_surface()
def create_nurbs_sphere_surface():
bpy.ops.surface.primitive_nurbs_surface_sphere_add()
return active_object()
def create_sphere_surface():
return create_nurbs_sphere_surface()
def create_nurbs_torus_surface():
bpy.ops.surface.primitive_nurbs_surface_torus_add()
return active_object()
def create_torus_surface():
return create_nurbs_torus_surface()
# Metaball
def create_metaball():
bpy.ops.object.metaball_add(type='BALL')
active_object()
def create_metaball_capsule():
bpy.ops.object.metaball_add(type='CAPSULE')
active_object()
def create_metaball_plane():
bpy.ops.object.metaball_add(type='PLANE')
active_object()
def create_metaball_ellipsoid():
bpy.ops.object.metaball_add(type='ELLIPSOID')
active_object()
def create_metaball_cube():
bpy.ops.object.metaball_add(type='CUBE')
active_object()
# Text
def create_text_object():
bpy.ops.object.text_add()
return active_object()
def create_text():
return create_text_object()
#endregion
#region OBJECTS - CONSTRAINTS
def add_constraint(type, ref = None, name = ""):
objref = get_object(ref)
new_con = objref.constraints.new(type)
if name :
new_con.name = name
for area in bpy.context.screen.areas:
if area.type == 'PROPERTIES':
area.tag_redraw()
return new_con
def get_constraint(name, ref = None):
objref = get_object(ref)
if name in objref.constraints:
return objref.constraints[name]
else:
return None
def get_constraints_by_type(type,ref = None):
objref = get_object(ref)
constraints = [con for con in objref.constraints if con.type == type]
return constraints
def remove_constraint(name = None, ref = None):
objref = get_object(ref)
if name is not None:
if is_string(name):
if name in objref.constraints:
mod = get_constraint(name,objref)
objref.constraints.remove(mod)
else:
objref.constraints.remove(name)
else:
remove_constraint(objref.constraints[0])
for area in bpy.context.screen.areas:
if area.type == 'PROPERTIES':
area.tag_redraw()
def add_camera_solver_constraint(ref = None, name = ""):
return add_constraint('CAMERA_SOLVER', ref, name)
def add_follow_track_constraint(ref = None, name = ""):
return add_constraint('FOLLOW_TRACK', ref, name)
def add_object_solver_constraint(ref = None, name = ""):
return add_constraint('OBJECT_SOLVER', ref, name)
def add_copy_location_constraint(ref = None, name = ""):
return add_constraint('COPY_LOCATION', ref, name)
def add_copy_rotation_constraint(ref = None, name = ""):
return add_constraint('COPY_ROTATION', ref, name)
def add_copy_scale_constraint(ref = None, name = ""):
return add_constraint('COPY_SCALE', ref, name)
def add_copy_transforms_constraint(ref = None, name = ""):
return add_constraint('COPY_TRANSFORMS', ref, name)
def add_limit_distance_constraint(ref = None, name = ""):
return add_constraint('LIMIT_DISTANCE', ref, name)
def add_limit_location_constraint(ref = None, name = ""):
return add_constraint('LIMIT_LOCATION', ref, name)
def add_limit_rotation_constraint(ref = None, name = ""):
return add_constraint('LIMIT_ROTATION', ref, name)
def add_limit_scale_constraint(ref = None, name = ""):
return add_constraint('LIMIT_SCALE', ref, name)
def add_maintain_volume_constraint(ref = None, name = ""):
return add_constraint('MAINTAIN_VOLUME', ref, name)
def add_transform_constraint(ref = None, name = ""):
return add_constraint('TRANSFORM', ref, name)
def add_transformation_constraint(ref = None, name = ""):
return add_constraint('TRANSFORM', ref, name)
def add_transform_cache_constraint(ref = None, name = ""):
return add_constraint('TRANSFORM_CACHE', ref, name)
def add_clamp_to_constraint(ref = None, name = ""):
return add_constraint('CLAMP_TO', ref, name)
def add_damped_track_constraint(ref = None, name = ""):
return add_constraint('DAMPED_TRACK', ref, name)
def add_locked_track_constraint(ref = None, name = ""):
return add_constraint('LOCKED_TRACK', ref, name)
def add_stretch_to_constraint(ref = None, name = ""):
return add_constraint('STRETCH_TO', ref, name)
def add_track_to_constraint(ref = None, name = ""):
return add_constraint('TRACK_TO', ref, name)
def add_action_constraint(ref = None, name = ""):
return add_constraint('ACTION', ref, name)
def add_armature_constraint(ref = None, name = ""):
return add_constraint('ARMATURE', ref, name)
def add_child_of_constraint(ref = None, name = ""):
return add_constraint('CHILD_OF', ref, name)
def add_floor_constraint(ref = None, name = ""):
return add_constraint('FLOOR', ref, name)
def add_follow_path_constraint(ref = None, name = ""):
return add_constraint('FOLLOW_PATH', ref, name)
def add_pivot_constraint(ref = None, name = ""):
return add_constraint('PIVOT', ref, name)
def add_shrinkwrap_constraint(ref = None, name = ""):
return add_constraint('SHRINKWRAP', ref, name)
#endregion
#region MODES
def set_mode(ref=None, newmode=None,):
if newmode is not None:
objref = get_object(ref)
bpy.context.view_layer.objects.active = objref
bpy.ops.object.mode_set(mode=newmode)
def get_mode():
return bpy.context.mode
def set_object_mode(ref=None):
set_mode(ref, 'OBJECT')
def object_mode(ref=None):
set_object_mode(ref)
def set_edit_mode(ref=None):
set_mode(ref, 'EDIT')
def edit_mode(ref=None):
set_edit_mode(ref)
def set_sculpt_mode(ref=None):
set_mode(ref, 'SCULPT')
def sculpt_mode(ref=None):
set_sculpt_mode(ref)
def set_vertex_paint_mode(ref=None):
set_mode(ref, 'VERTEX_PAINT')
def vertex_paint_mode(ref=None):
set_vertex_paint_mode(ref)
def set_weight_paint_mode(ref=None):
set_mode(ref, 'WEIGHT_PAINT')
def weight_paint_mode(ref=None):
set_weight_paint_mode(ref)
def set_texture_paint_mode(ref=None):
set_mode(ref, 'TEXTURE_PAINT')
def texture_paint_mode(ref=None):
set_texture_paint_mode(ref)
def set_pose_mode(ref=None):
set_mode(ref, 'POSE')
def pose_mode(ref=None):
set_pose_mode(ref)
#endregion
#region SCENES
def get_scene():
return bpy.context.scene
#endregion
#region VISIBILITY
def hide_object(ref=None):
objs = get_objects(ref)
for obj in objs:
obj.hide_set(True)
def hide(ref = None):
hide_object(ref)
def show_object(ref = None):
objs = get_objects(ref)
for obj in objs:
obj.hide_set(False)
def show(ref = None):
show_object(ref)
def unhide(ref = None):
show_object(ref)
def unhide_object(ref = None):
show_object(ref)
def hide_in_viewport(ref):
objs = get_objects(ref)
for obj in objs:
obj.hide_viewport = True
def show_in_viewport(ref):
objs = get_objects(ref)
for obj in objs:
obj.hide_viewport = False
def unhide_in_viewport(ref):
show_in_viewport(ref)
def hide_in_render(ref):
objs = get_objects(ref)
for obj in objs:
obj.hide_render = True