-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathDuplicate_Along_Curve.py
87 lines (67 loc) · 2.82 KB
/
Duplicate_Along_Curve.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
# ##### BEGIN GPL LICENSE BLOCK #####
#
# 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 2
# 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, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
bl_info = {
"name": "Duplicate Along Curve",
"category": "Object",
"description": "Select a curve and an object, to duplicate object along curve.",
"author": "Andreas Strømberg",
"wiki_url": "https://github.com/Stromberg90/Scripts/tree/master/Blender",
"tracker_url": "https://github.com/Stromberg90/Scripts/issues",
"blender": (2, 80, 0),
"version": (1, 0)
}
import bpy
def main(context):
if bpy.context.selected_objects[1].type == 'MESH' and bpy.context.selected_objects[0].type == 'CURVE':
selected_curve = bpy.context.selected_objects[0]
selected_object = bpy.context.selected_objects[1]
elif bpy.context.selected_objects[1].type == 'CURVE' and bpy.context.selected_objects[0].type == 'MESH':
selected_curve = bpy.context.selected_objects[1]
selected_object = bpy.context.selected_objects[0]
else:
return
bpy.ops.object.transform_apply(scale=True)
bpy.ops.object.select_all(action='DESELECT')
selected_object.select_set(True)
context.view_layer.objects.active = selected_object
array_modifier = selected_object.modifiers.new(name='DUPLICATE_ARRAY', type='ARRAY')
array_modifier.fit_type = 'FIT_CURVE'
array_modifier.curve = selected_curve
curve_modifier = selected_object.modifiers.new(name='DUPLICATE_CURVE', type='CURVE')
curve_modifier.object = selected_curve
selected_object.location = selected_curve.location
class DuplicateAlongCurve(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.duplicate_along_curve"
bl_label = "Duplicate Along Curve"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if len(context.selected_objects) == 2:
return context.active_object is not None
else:
return False
def execute(self, context):
main(context)
return {'FINISHED'}
def register():
bpy.utils.register_class(DuplicateAlongCurve)
def unregister():
bpy.utils.unregister_class(DuplicateAlongCurve)
if __name__ == "__main__":
register()