OpenSCAD would be well suited for creating something made up of relatively simple shapes, where different dimensions are needed for some parts of the shapes - like the diameters and offsets of your stepper motor shafts.
A solution in OpenSCAD could look something like this:
outer_diameter = 8.5; //Outer diameter of the adapter
stepper_length = 12; //Length of the stepper shaft
stepper_diameter = 4; //Diameter of the stepper shaft
stepper_d_offset = 1.6; //Offset from the center of the shaft to the plane of the D
//4mm shaft: d = 4, offset = 1.6
//5mm shaft: d = 5, offset = 2
//6mm shaft: d = 6, offset = 2.5
thickness_mid = 2; //Thickness of the massive section between stepper and lego shafts
lego_length = 10; //Length of the lego shaft
lego_diameter = 4.9; //Outer diameter of the lego shaft
lego_internal_width = 1.9; //Width of the slots for the shaft
lego_corner_radius = 0.5;
cutout_size = lego_diameter;
cutout_translate = cutout_size / 2 + lego_internal_width / 2;
$fn = 128; //Accuracy / resolution of circles
eps = 0.01;
module fillet_square(width, radius) {
translate([radius - width / 2, radius - width / 2, 0])
minkowski() {
square(width - 2 * radius);
circle(radius);
}
}
color(0,0.5)
union(){
linear_extrude(height = stepper_length + eps) {
difference() {
circle(d = outer_diameter);
difference() {
circle(d = stepper_diameter);
translate([0, stepper_d_offset + stepper_diameter / 2, 0]) {
square(size = stepper_diameter, center = true);
}
}
}
}
translate([0, 0, stepper_length]) {
linear_extrude(height = thickness_mid) {
circle(d = outer_diameter);
}
}
translate([0, 0, stepper_length + thickness_mid - eps]) {
linear_extrude(height = lego_length + eps) {
difference() {
circle(d = outer_diameter);
difference() {
circle(d = lego_diameter);
translate([cutout_translate, cutout_translate, 0]) {
fillet_square(cutout_size, lego_corner_radius);
}
translate([cutout_translate, -cutout_translate, 0]) {
fillet_square(cutout_size, lego_corner_radius);
}
translate([-cutout_translate, cutout_translate, 0]) {
fillet_square(cutout_size, lego_corner_radius);
}
translate([-cutout_translate, -cutout_translate, 0]) {
fillet_square(cutout_size, lego_corner_radius);
}
}
}
}
}
}

You can then export your .stl file (or any other format) for 3D-printing from OpenSCAD.