I would love to write some add ins but I am not familiar enough with the Blender Python syntax. My languages are VBA, Javascript and PHP. I understand programming concepts but am very lost as to what libraries to include and the syntax to accomplish the task below.
I would like to find or create a script that will allow me to iterate through all segments on a curve. This functionality is already in Daz Hexagon which I am happily working on abandoning. Basically you would select an object and then in edit mode you can select a single segment, press the hotkey to run the script that would select the next segment and deselet the previous one.
Anybody that is really good at code think they can help me with this? I want to learn eventually but i think I need to look at some examples in order to fully understand the libraries and syntax.
import bpy
o = bpy.context.object
sel = [(i,x) for i in o.data.splines for x,j in enumerate(i.bezier_points) if j.select_control_point]
for i in sel:
i[0].bezier_points[i[1]].select_control_point = False
for i in sel:
if i[1]+1 < len(i[0].bezier_points):
i[0].bezier_points[i[1]+1].select_control_point = True
Wow I am so thankful that you posted this. I tried it out and its not quite working. The curves I will be using are almost always going to be circles. I have been playing around with
bpy.ops.curve.select_next()
But at predicted it selects the next point while keeping the previous one selected. Also if I have the last point on the circle selected it does not go to the first. Isn’t there a simple loop like
for v in bpy.ops.curve.points: if v.selected == true
I must be missing something. Thanks again for the reply.
import bpy
o = bpy.context.object
sel = [(i,x) for i in o.data.splines for x,j in enumerate(i.bezier_points) if j.select_control_point]
for i in sel:
i[0].bezier_points[i[1]].select_control_point = False
for i in sel:
if i[1]+1 < len(i[0].bezier_points):
i[0].bezier_points[i[1]+1].select_control_point = True
else:
i[0].bezier_points[0].select_control_point = True
Excellent Excellent Excellent Work!!! This is functioning. I wish I could understand the Sel object a little bit better. All I can get out of it so far is that it is an array of some sorts but an If statement and loop within the declaration is something I have not seen before. Is this just Python practice?? Ive never seen it in my other languages. Thanks again.
Hi JuhaW, I just wanted to thank you for putting together that script so long ago. I decided to try putting it into an add on and it works great.
bl_info = {
"name": "Select Next Curve Vertex",
"author": "James Erickson - ExcelledSoftware and JuhaW from blenderartists",
"version": (1, 0),
"blender": (2, 79, 0),
"location": "VIEW3D > Tool Shelf > zzz",
"description": "Selects the next point or vertex in a curve",
"warning": "Only works with curves",
"wiki_url": "",
"category": "Selection",
}
import bpy
def main(context):
#main code below written by JuhaW from blenderartists.org
o = bpy.context.object
sel = [(i,x) for i in o.data.splines for x,j in enumerate(i.bezier_points) if j.select_control_point]
for i in sel:
i[0].bezier_points[i[1]].select_control_point = False
for i in sel:
if i[1]+1 < len(i[0].bezier_points):
i[0].bezier_points[i[1]+1].select_control_point = True
else:
i[0].bezier_points[0].select_control_point = True
#end of normal code all below written by James Erickson
class SelectNextCurveVertex(bpy.types.Operator):
"""Tooltip"""
bl_idname = "myops.select_next_curve_vertex"
bl_label = "Select The Next Vertex"
def execute(self, context):
main(context)
return {'FINISHED'}
class SelectNextCurveVertexPanel(bpy.types.Panel):
"""Creates a Panel in the Tool Shelf"""
bl_label = "Select Next Curve Vertex Panel"
bl_idname = "select_next_vertex_id"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_category = "zz"
# draw the panel
def draw(self, context):
layout = self.layout
obj = context.object
#add the labels and controls
row = layout.row()
row.label(text="Select Next Vertex", icon='CURVE_DATA')
row = layout.row()
row.label(text="Current Selected: " + obj.name)
row = layout.row()
row.operator("myops.select_next_curve_vertex")
def register():
bpy.utils.register_class(SelectNextCurveVertex)
bpy.utils.register_class(SelectNextCurveVertexPanel)
def unregister():
bpy.utils.unregister_class(SelectNextCurveVertex)
bpy.utils.unregister_class(SelectNextCurveVertexPanel)
# allow to run from text editor
if __name__ == "__main__":
register()