draw cylinder between 2 vectors

hi

how can i draw a cylinder between 2 vectors ?
so that one end starts at (x,y,z) and the other end ends at (x1,y1,z1)

thanks for any help

just add a bevel curve between the 2 points !

salutations

RickyBlender

could you elaborate on that ?

thanks

@sc3sc3,
You could use something like this below. You need to select two or more objects, those will indicate location A and location B. This then creates a beveled curve between the two.

import bpy

list = []
# Get selected objects
obnames =  bpy.context.selected_objects
for a in obnames:  
    list.append(a)
    a.select = False

check_select = len(obnames)

if check_select < 2:
	print("Select at least two objects")
else:
	# Create curve object
	draw_curve = bpy.data.curves.new('draw_curve','CURVE')
	draw_curve.dimensions = '3D'
	spline = draw_curve.splines.new('BEZIER')
	spline.bezier_points.add(len(list)-1)
	curve = bpy.data.objects.new('curve',draw_curve)
	bpy.context.scene.objects.link(curve)

	# Curve settings for new curve
	draw_curve.resolution_u = 64
	draw_curve.fill_mode = 'FULL'
	draw_curve.bevel_depth = 0.5
	draw_curve.bevel_resolution = 5

	# Assign bezier points to selection object locations
	for i in range(len(list)):
	    p = spline.bezier_points[i]
	    p.co = list[i].location
	    p.handle_right_type="VECTOR"
	    p.handle_left_type="VECTOR"

	bpy.context.scene.objects.active = curve
	bpy.ops.object.mode_set(mode='OBJECT')

thank you very much crazycourier for this example !

don’t know anything about ‘beveled curves’
so have to study a bit

cool :slight_smile:

@crazycourier
Rather nice script example :yes:

You can also make a cylinder and then align it along the line connecting 2 points.


import bpy

def AlignZ(v1,v2):  # Will align Z axis with X axis as 'UP' 
    dvec=v2-v1
    rotation_quat = dvec.to_track_quat('Z', 'X')
    return rotation_quat

cylinder=      #your cylinder object
loc1=           #location of end 1
loc2=           #location of end 1
#Cylinder should be in quaternion rotation mode 
cylinder.rotation_quaternion=AlignX(loc1,loc2)

After this simply place cylinder on center of line(distance) between 2 points.