Page Menu
Home
Search
Configure Global Search
Log In
Paste
P312
Curve extrude, sample code
Active
Public
Actions
Authored by
Campbell Barton (campbellbarton)
on Jan 12 2016, 1:53 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Tags
Good First Issue
Subscribers
None
import
bpy
import
bmesh
from
math
import
pi
,
sin
,
sqrt
,
radians
,
degrees
from
mathutils
import
Vector
bl_info
=
{
"name"
:
"Curve extrude"
,
"author"
:
"Juha Wiiala"
,
"version"
:
(
0
,
1
,
0
),
"blender"
:
(
2
,
76
,
0
),
"location"
:
"Curve"
,
"description"
:
"Alt+D to extrude two curve points"
,
"warning"
:
"beta"
,
"wiki_url"
:
""
,
"category"
:
""
,
}
# store keymaps here to access after registration
addon_keymaps
=
[]
class
CurveExtrudePoints
(
bpy
.
types
.
Operator
):
bl_idname
=
"curve.extrudepoints"
bl_label
=
"Extrude curve points"
bl_options
=
{
'REGISTER'
,
'UNDO'
}
# enable undo for the operator.
def
execute
(
self
,
context
):
print
(
"curve extrude execute"
)
return
{
'FINISHED'
}
def
invoke
(
self
,
context
,
value
):
o
=
context
.
object
#curve bezier point coord
#vco = [p.co for x in o.data.splines for p in x.bezier_points if p.select_control_point]
#points = [p for x in o.data.splines for p in x.bezier_points if p.select_control_point]
ci
=
[
i
for
x
in
o
.
data
.
splines
for
i
,
p
in
enumerate
(
x
.
bezier_points
)
if
p
.
select_control_point
]
print
(
ci
)
if
len
(
ci
)
==
2
:
#first and last points are selected
if
ci
[
0
]
==
0
and
ci
[
1
]
==
len
(
o
.
data
.
splines
.
active
.
bezier_points
)
-
1
:
print
(
"first and last points are selected"
)
bpy
.
ops
.
curve
.
subdivide
(
number_cuts
=
2
)
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
0
]]
.
select_control_point
=
False
o
.
data
.
splines
[
0
]
.
bezier_points
[
-
3
]
.
select_control_point
=
False
o
.
data
.
splines
[
0
]
.
bezier_points
[
-
1
]
.
co
=
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
0
]]
.
co
o
.
data
.
splines
[
0
]
.
bezier_points
[
-
2
]
.
co
=
o
.
data
.
splines
[
0
]
.
bezier_points
[
-
3
]
.
co
else
:
bpy
.
ops
.
curve
.
subdivide
(
number_cuts
=
2
)
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
0
]]
.
select_control_point
=
False
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
1
]
+
2
]
.
select_control_point
=
False
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
0
]
+
1
]
.
co
=
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
0
]]
.
co
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
0
]
+
2
]
.
co
=
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
1
]
+
2
]
.
co
elif
len
(
ci
)
>
2
:
print
(
"more than 2 points selected"
)
bpy
.
ops
.
curve
.
select_all
(
action
=
'DESELECT'
)
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
0
]]
.
select_control_point
=
True
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
1
]]
.
select_control_point
=
True
bpy
.
ops
.
curve
.
subdivide
(
number_cuts
=
1
)
bpy
.
ops
.
curve
.
select_all
(
action
=
'DESELECT'
)
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
-
1
]]
.
select_control_point
=
True
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
-
1
]
+
1
]
.
select_control_point
=
True
bpy
.
ops
.
curve
.
subdivide
(
number_cuts
=
1
)
bpy
.
ops
.
curve
.
select_all
(
action
=
'DESELECT'
)
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
0
]
+
1
]
.
co
=
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
0
]]
.
co
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
-
1
]
+
1
]
.
co
=
o
.
data
.
splines
[
0
]
.
bezier_points
[
ci
[
-
1
]
+
2
]
.
co
for
i
in
range
(
ci
[
0
]
+
1
,
ci
[
-
1
]
+
2
):
o
.
data
.
splines
[
0
]
.
bezier_points
[
i
]
.
select_control_point
=
True
#o.data.splines[0].bezier_points[i].select_left_handle = False
#o.data.splines[0].bezier_points[i].select_right_handle = False
bpy
.
ops
.
transform
.
translate
(
'INVOKE_DEFAULT'
)
return
{
'FINISHED'
}
#curve extrude
#store selected points and their index
#SUBDIVIDE part
#deselect all
#select 2 points from the beginning and from the end
#subdivide 1
def
register
():
bpy
.
utils
.
register_module
(
__name__
)
# handle the keymap
wm
=
bpy
.
context
.
window_manager
km
=
wm
.
keyconfigs
.
addon
.
keymaps
.
new
(
name
=
'Curve'
,
space_type
=
'EMPTY'
,
region_type
=
'WINDOW'
)
kmi
=
km
.
keymap_items
.
new
(
CurveExtrudePoints
.
bl_idname
,
'D'
,
'PRESS'
)
addon_keymaps
.
append
(
km
)
def
unregister
():
bpy
.
utils
.
unregister_module
(
__name__
)
# handle the keymap
wm
=
bpy
.
context
.
window_manager
for
km
in
addon_keymaps
:
wm
.
keyconfigs
.
addon
.
keymaps
.
remove
(
km
)
# clear the list
addon_keymaps
.
clear
()
if
__name__
==
"__main__"
:
try
:
unregister
()
except
:
pass
register
()
# to create curve points
#o.data.splines[0].bezier_points.add(1)
#bpy.ops.curve.make_segment()
#delete curve segment
#bpy.ops.curve.delete(type='SEGMENT')
Event Timeline
Campbell Barton (campbellbarton)
edited the content of this paste.
(Show Details)
Jan 12 2016, 1:53 PM
Campbell Barton (campbellbarton)
changed the title of this paste from untitled to
Curve extrude, sample code
.
Campbell Barton (campbellbarton)
updated the paste's language from
autodetect
to
python
.
Campbell Barton (campbellbarton)
added a project:
Good First Issue
.
Campbell Barton (campbellbarton)
mentioned this in
T47169: Improve Curve extrude
.
•
spam (sportsyearly1)
mentioned this in
•
spam (sportsyearly1)
.
Dec 28 2022, 7:37 PM
Log In to Comment