"""Paper tail threading rope drive, authored as a v4 articulated asset."""
import math
import os
import sys
import bpy

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import v4lib as v4

v4.reset()

# Materials: industrial frame, turned sheaves, dark braided ropes, and paper stock.
paint = v4.painted("machine_blue_gray", (0.16, 0.27, 0.34), roughness=0.31)
paint_dark = v4.painted("deep_blue_gray", (0.09, 0.15, 0.19), roughness=0.34)
steel = v4.metal("zinc_steel", (0.72, 0.76, 0.78), roughness=0.28)
aluminum = v4.metal("turned_aluminum", (0.60, 0.65, 0.67), roughness=0.26)
dark_metal = v4.metal("bearing_black_oxide", (0.12, 0.15, 0.16), roughness=0.38, brushed=False)
rope_mats = (
    v4.rubber("braided_rope_graphite", (0.028, 0.038, 0.042), roughness=0.84),
    v4.rubber("braided_rope_oxblood", (0.24, 0.022, 0.016), roughness=0.82),
)
rope_traces = (
    v4.rubber("rope_lime tracer", (0.72, 0.82, 0.16), roughness=0.72),
    v4.rubber("rope_coral tracer", (0.92, 0.21, 0.10), roughness=0.72),
)
paper = v4.mat("paper_tail", (0.91, 0.85, 0.68), roughness=0.78)
paper.node_tree.nodes.get("Principled BSDF").inputs["Alpha"].default_value = 0.58
paper.surface_render_method = "DITHERED"
paper.diffuse_color = (0.91, 0.85, 0.68, 0.58)
ink = v4.mat("dark_ink", (0.06, 0.085, 0.09), roughness=0.55)
warning = v4.painted("safety_ochre", (0.88, 0.49, 0.08), roughness=0.4)

# Envelope: roughly 1.75 x 0.62 x 0.86 m; X is the threading direction.
X0, X1 = -0.82, 0.82
YLANES = (-0.00675, 0.00675)
ZTOP, ZBOT = 0.57, 0.35
R_END, R_GUIDE = 0.11, 0.060
frame = v4.body("frame")

# Welded, leveling-foot frame and elevated rope support rails.
v4.box("base_long_left", (1.68, 0.045, 0.065), (0, -0.245, 0.12), bevel=0.009, material=paint, body=frame)
v4.box("base_long_right", (1.68, 0.045, 0.065), (0, 0.245, 0.12), bevel=0.009, material=paint, body=frame)
for x in (-0.69, -0.23, 0.23, 0.69):
    v4.box(f"base_crossmember_{x:+.2f}", (0.055, 0.49, 0.055), (x, 0, 0.12), bevel=0.006, material=paint_dark, body=frame)
for x in (-0.69, 0.69):
    for y in (-0.225, 0.225):
        v4.box(f"upright_{x:+.2f}_{y:+.2f}", (0.045, 0.045, 0.52), (x, y, 0.40), bevel=0.006, material=paint, body=frame)
        v4.box(f"gusset_{x:+.2f}_{y:+.2f}", (0.11, 0.075, 0.12), (x, y, 0.18), bevel=0.006, material=paint_dark, body=frame)
for y in (-0.245, 0.245):
    v4.box(f"upper_side_rail_{y:+.3f}", (1.58, 0.045, 0.06), (0, y, 0.66), bevel=0.007, material=paint, body=frame)
    v4.box(f"inner_bearing_rail_{y:+.3f}", (1.56, 0.024, 0.035), (0, y * 0.72, 0.49), bevel=0.004, material=paint_dark, body=frame)
for y in (-0.245, 0.245):
    v4.box(f"rope_bed_{y:+.3f}", (1.57, 0.028, 0.018), (0, y * 0.72, 0.305), bevel=0.003, material=steel, body=frame)

# Bearing bars support every fixed guide axle and tie the roller standards to the frame.
support_ys = sorted(set(round(y + side * 0.010, 4) for y in YLANES for side in (-1, 1)))
for y in support_ys:
    for row_z, label in ((0.4885, "upper"), (0.3385, "return")):
        v4.box(f"{label}_sheave_support_rail_{y:+.4f}", (1.15, 0.008, 0.022), (0.025, y, row_z),
               bevel=0.002, material=paint_dark, body=frame)
# Ladder ties join each pair of support rails under its rope lane.
for lane in YLANES:
    for x in (-0.54, 0.48):
        for z, label in ((0.4885, "upper"), (0.3385, "return")):
            v4.box(f"{label}_lane_tie_{lane:+.3f}_{x:+.2f}", (0.035, 0.020, 0.022),
                   (x, lane, z), bevel=0.002, material=paint, body=frame)
# Outer upper supports land on the existing inner bearing rail. Return rails use end posts.
for lane in YLANES:
    outer_y = lane + (0.010 if lane > 0 else -0.010)
    frame_rail_y = 0.1764 if lane > 0 else -0.1764
    for x in (-0.54, 0.48):
        v4.box(f"upper_support_crosshead_{lane:+.3f}_{x:+.2f}",
               (0.035, abs(frame_rail_y - outer_y), 0.022),
               (x, (frame_rail_y + outer_y) / 2, 0.4885), bevel=0.002, material=paint, body=frame)
        v4.box(f"return_support_stanchion_{lane:+.3f}_{x:+.2f}", (0.022, 0.008, 0.128),
               (x, outer_y, 0.414), bevel=0.002, material=paint, body=frame)

# Inner bearing rails rise into the upper side rails, closing the roller support spine
# into the welded chassis instead of leaving the guide row as a floating subassembly.
for y in (-0.1764, 0.1764):
    for x in (-0.68, 0.68):
        v4.box(f"inner_rail_upright_{y:+.4f}_{x:+.2f}", (0.032, 0.032, 0.145),
               (x, y, 0.565), bevel=0.002, material=paint, body=frame)
        sy = 1 if y > 0 else -1
        v4.box(f"inner_rail_side_tie_{sy}_{x:+.2f}", (0.032, 0.069, 0.032),
               (x, sy * 0.2107, 0.64), bevel=0.002, material=paint, body=frame)
        v4.box(f"rope_bed_side_tie_{sy}_{x:+.2f}", (0.035, 0.069, 0.022),
               (x, sy * 0.2107, 0.305), bevel=0.002, material=paint, body=frame)

# The carriage rails are carried by long brackets at the motor-side end,
# outside the full swept envelope of the moving shoes.
for rail_y in (-0.040, 0.040):
    sy = 1 if rail_y > 0 else -1
    v4.box(f"tension_rail_frame_tie_{rail_y:+.3f}", (0.035, 0.245 - abs(rail_y), 0.022),
           (0.50, sy * (abs(rail_y) + 0.245) / 2, 0.295),
           bevel=0.002, material=paint, body=frame)

# Four adjustable leveling feet (the broad pads sit exactly on the ground plane).
for x in (-0.70, 0.70):
    for y in (-0.235, 0.235):
        v4.cylinder(f"foot_pad_{x}_{y}", 0.035, 0.012, (x, y, 0.006), bevel=0.002, material=dark_metal, body=frame)
        v4.cylinder(f"leveling_bolt_{x}_{y}", 0.009, 0.09, (x, y, 0.055), bevel=0.001, material=steel, body=frame)
        v4.cylinder(f"foot_locknut_{x}_{y}", 0.018, 0.012, (x, y, 0.083), bevel=0.001, material=aluminum, body=frame)

# Keyed drive hubs have a real shaft bore and an open keyway rather than a solid
# cylinder intersecting the transverse shaft.
def keyed_annulus(name, x, y, z, outer_r, bore_r, depth, side, body):
    slot_w = 0.005
    outer_a = math.asin(slot_w / (2 * outer_r))
    inner_a = math.asin(slot_w / (2 * bore_r))
    n = 64
    outer_angles = [-outer_a + i * (2 * math.pi + 2 * outer_a) / (n - 1) for i in range(n)]
    inner_angles = [inner_a - i * (2 * math.pi + 2 * inner_a) / (n - 1) for i in range(n)]
    outline = [(outer_r * math.cos(a), outer_r * math.sin(a)) for a in outer_angles]
    outline += [(bore_r * math.cos(a), bore_r * math.sin(a)) for a in inner_angles]
    if side < 0:
        rot, loc_y = (math.pi / 2, 0, 0), y + depth / 2
    else:
        rot = (-math.pi / 2, 0, 0)
        outline = [(px, -pz) for px, pz in outline]
        loc_y = y - depth / 2
    v4.extrude(name, outline, depth, loc=(x, loc_y, z), rot=rot,
               bevel=0.00035, material=dark_metal, body=body)


# Turned sheaves: a lathed V profile makes the rope seat legible from the hero views.
def sheave(name, body, x, y, z, radius, width, drive=False, wheel_material=aluminum):
    axis_y = (math.pi / 2, 0, 0)
    inner = 0.012 if drive else 0.0
    profile = [(inner, -width/2), (radius - 0.004, -width/2),
               (radius, -width*0.27), (radius - 0.008, 0),
               (radius, width*0.27), (radius - 0.004, width/2),
               (inner, width/2), (inner, -width/2)]
    v4.lathe(name + "_bored_V_groove", profile, (x, y, z), rot=axis_y,
             material=wheel_material, body=body)
    flange_r = radius
    flange_d = max(0.005, width * 0.12)
    # Each lane is an inward-facing pair. Keep the cheek/flange on the outside
    # so the two narrow sheaves can run close together around the paper tail.
    outer_sign = 1 if y > 0 else -1
    side = outer_sign
    v4.cylinder(name + f"_flange_{side}", flange_r, flange_d,
                (x, y + side * (width * 0.44), z), rot=axis_y,
                bevel=0.0012, material=wheel_material, body=body)
    hub_depth = max(0.0025, width * 0.25)
    v4.cylinder(name + f"_hub_{side}", radius * 0.34, hub_depth,
                (x, y + side * (width * 0.55), z), rot=axis_y,
                bevel=0.0007, material=dark_metal, body=body)
    v4.cylinder(name + f"_retainer_{side}", radius * 0.19, max(0.001, width * 0.12),
                (x, y + side * (width * 0.68), z), rot=axis_y,
                bevel=0.0004, material=steel, body=body)
    # The fine dark annulus at the web edge reads as a machined rope groove.
    v4.torus(name + "_groove_liner", radius * 0.78, 0.0035, (x, y, z), rot=axis_y,
             material=dark_metal, body=body)
    # Six small face recesses/fasteners on the exposed cheek.
    face_y = y + outer_sign * width * 0.51
    for i in range(6):
        a = 2 * math.pi * i / 6
        v4.cylinder(name + f"_face_bolt_{i}", 0.0025, 0.002,
                    (x + radius * 0.58 * math.cos(a), face_y, z + radius * 0.58 * math.sin(a)),
                    rot=axis_y, segments=16, bevel=0.0004, material=steel, body=body)
    if drive:
        keyed_annulus(name + "_bored_keyed_drive_hub", x,
                      y + outer_sign * width * 0.80, z,
                      radius * 0.25, 0.011, 0.012, outer_sign, body)

# Main drive and tension sheaves; each lane has an independent traveling rope loop.
DRIVE_X, TENSION_X, MID_Z = -0.72, 0.72, 0.46
ROPE_TENSION_X = TENSION_X + 0.060
carriage = v4.body("tension_carriage")
# One rigid cross carriage keeps both narrow rope tracks synchronized. Its
# shoes visibly ride on two shared guide rails and carry both tension yokes.
for yy in (-0.040, 0.040):
    v4.box(f"tension_carriage_slide_shoe_{yy:+.3f}", (0.18, 0.014, 0.035),
           (TENSION_X, yy, 0.295), bevel=0.003, material=dark_metal, body=carriage)
v4.box("tension_carriage_bridge", (0.12, 0.085, 0.045), (TENSION_X, 0, 0.33),
       bevel=0.005, material=paint, body=carriage)
v4.box("tension_carriage_scale_tab", (0.055, 0.009, 0.025),
       (TENSION_X, -0.047, 0.34), bevel=0.002, material=warning, body=carriage)
v4.joint("tension_carriage_slide", "prismatic", frame, carriage,
         origin=(TENSION_X, 0, 0.30), axis=(1, 0, 0), limits=(0.0, 0.060))
for lane_i, y in enumerate(YLANES):
    side = "L" if lane_i == 0 else "R"
    drive = v4.body(f"drive_sheave_{side}")
    sheave(f"drive_{side}", drive, DRIVE_X, y, MID_Z, R_END, 0.0095, drive=True)
    v4.joint(f"drive_{side}_spin", "continuous", frame, drive,
             origin=(DRIVE_X, y, MID_Z), axis=(0, 1, 0))

    # Narrow cheek plates flank each tension sheave and tie into the common bridge.
    for sy in ((-1,) if y < 0 else (1,)):
        v4.box(f"tension_{side}_yoke_cheek_{sy}", (0.032, 0.0055, 0.22),
               (TENSION_X, y + sy * 0.010, MID_Z), bevel=0.0015, material=paint, body=carriage)
    tension = v4.body(f"tension_sheave_{side}")
    sheave(f"tension_{side}", tension, TENSION_X, y, MID_Z, R_END, 0.0095)
    v4.joint(f"tension_{side}_spin", "continuous", carriage, tension,
             origin=(TENSION_X, y, MID_Z), axis=(0, 1, 0))

# Six upper-run and four return-run guide rollers per lane with fixed bearing standards.
upper_xs = (-0.49, -0.27, -0.05, 0.17, 0.39, 0.59)
lower_xs = (-0.48, -0.20, 0.08, 0.36)
for lane_i, y in enumerate(YLANES):
    side = "L" if lane_i == 0 else "R"
    for row, xs, z in (("upper", upper_xs, ZTOP - R_GUIDE), ("return", lower_xs, ZBOT + R_GUIDE)):
        for si, x in enumerate(xs):
            # Bearing pedestals straddle the wheel. Their round caps visually seat its axle.
            for sy in (-1, 1):
                by = y + sy * 0.010
                v4.box(f"{row}_{side}_{si}_fork_cheek_{sy}", (0.040, 0.008, 0.112),
                       (x, by, z - 0.005), bevel=0.004, material=paint_dark, body=frame)
                v4.rod(f"{row}_{side}_{si}_fork_arm_a_{sy}",
                       (x - 0.022, by, z - 0.050), (x, by, z), 0.0032,
                       material=paint, body=frame)
                v4.rod(f"{row}_{side}_{si}_fork_arm_b_{sy}",
                       (x + 0.022, by, z - 0.050), (x, by, z), 0.0032,
                       material=paint, body=frame)
                v4.cylinder(f"{row}_{side}_{si}_bearing_cap_{sy}", 0.018, 0.004,
                            (x, by + sy * 0.004, z), rot=(math.pi / 2, 0, 0),
                            bevel=0.001, material=steel, body=frame)
                v4.cylinder(f"{row}_{side}_{si}_cap_screw_{sy}", 0.0035, 0.002,
                            (x, by + sy * 0.0065, z), rot=(math.pi / 2, 0, 0),
                            segments=16, bevel=0.0004, material=dark_metal, body=frame)
            roller = v4.body(f"guide_sheave_{side}_{row}_{si}")
            sheave(f"guide_{side}_{row}_{si}", roller, x, y, z, R_GUIDE, 0.012,
                   wheel_material=dark_metal)
            v4.joint(f"guide_{side}_{row}_{si}_spin", "continuous", frame, roller,
                     origin=(x, y, z), axis=(0, 1, 0))

# A transverse drive axle is supported in bearing blocks bolted to the side rails.
# The grooved sheaves rotate on this shaft while the frame remains fixed.
v4.cylinder("drive_transverse_shaft", 0.010, 0.49, (DRIVE_X, 0, MID_Z),
            rot=(math.pi / 2, 0, 0), bevel=0.001, material=steel, body=frame)
for y in (-0.245, 0.245):
    v4.box(f"drive_pillow_block_{y:+.3f}", (0.12, 0.055, 0.13), (DRIVE_X, y, MID_Z),
           bevel=0.006, material=paint_dark, body=frame)
    v4.cylinder(f"drive_pillow_cap_{y:+.3f}", 0.025, 0.058,
                (DRIVE_X, y, MID_Z), rot=(math.pi / 2, 0, 0), bevel=0.002, material=steel, body=frame)
    v4.box(f"drive_pillow_upright_{y:+.3f}", (0.032, 0.032, 0.17),
           (DRIVE_X, y, 0.575), bevel=0.003, material=paint, body=frame)

# Frame-mounted stops and carriage adjustment screw details.
# Shared long guide rails and screw keep the single carriage square over 60 mm travel.
for yy in (-0.040, 0.040):
    v4.box(f"tension_carriage_guide_rail_{yy:+.3f}", (0.54, 0.014, 0.012),
           (0.72, yy, 0.295), bevel=0.002, material=steel, body=frame)
for x in (0.45, 0.99):
    v4.box(f"tension_carriage_end_stop_{x:.2f}", (0.016, 0.10, 0.052),
           (x, 0, 0.30), bevel=0.003, material=paint_dark, body=frame)
for x, label in ((0.45, "MIN"), (0.99, "MAX")):
    v4.text(f"tension_stop_label_{label}", label, 0.008,
            loc=(x, -0.051, 0.295), rot=(math.pi / 2, 0, 0),
            extrude_depth=0.00025, material=steel, body=frame)
v4.rod("tension_carriage_adjuster", (0.44, 0, 0.34), (0.99, 0, 0.34), 0.005,
       material=steel, body=frame)
v4.cylinder("tension_carriage_adjuster_knob", 0.019, 0.025, (0.97, 0, 0.34),
            rot=(0, math.pi / 2, 0), bevel=0.002, material=warning, body=frame)
# Visible double-acting take-up cylinder: fixed barrel on the chassis and a polished
# translating rod/clevis in the existing carriage body.
for x in (0.45, 0.63):
    v4.box(f"takeup_cylinder_frame_mount_{x:.2f}", (0.025, 0.052, 0.052),
           (x, -0.190, 0.245), bevel=0.004, material=paint_dark, body=frame)
    v4.rod(f"takeup_cylinder_mount_strut_{x:.2f}", (x, -0.190, 0.255),
           (x, -0.040, 0.295), 0.006, material=paint, body=frame)
v4.cylinder("takeup_cylinder_barrel", 0.022, 0.22, (0.54, -0.190, 0.245),
            rot=(0, math.pi / 2, 0), bevel=0.003, material=paint_dark, body=frame)
v4.cylinder("takeup_cylinder_end_cap", 0.025, 0.014, (0.65, -0.190, 0.245),
            rot=(0, math.pi / 2, 0), bevel=0.002, material=aluminum, body=frame)
v4.cylinder("takeup_cylinder_rod", 0.008, 0.16, (0.65, -0.190, 0.245),
            rot=(0, math.pi / 2, 0), bevel=0.0015, material=steel, body=carriage)
v4.box("takeup_rod_clevis", (0.024, 0.044, 0.044), (TENSION_X, -0.190, 0.245),
       bevel=0.004, material=paint, body=carriage)
v4.cylinder("takeup_clevis_pin", 0.006, 0.052, (TENSION_X, -0.190, 0.245),
            rot=(math.pi / 2, 0, 0), bevel=0.001, material=steel, body=carriage)
v4.rod("takeup_clevis_carriage_link", (TENSION_X, -0.175, 0.255),
       (TENSION_X, -0.035, 0.305), 0.007, material=paint, body=carriage)

# Endless ropes follow tangent top/bottom runs with semicircular end turns.
def rope_loop_points(y, resolution=20):
    pts = []
    pts.append((DRIVE_X, y, ZTOP))
    pts.append((ROPE_TENSION_X, y, ZTOP))
    for i in range(1, resolution + 1):
        a = math.pi / 2 - math.pi * i / resolution
        pts.append((ROPE_TENSION_X + R_END * math.cos(a), y, MID_Z + R_END * math.sin(a)))
    pts.append((DRIVE_X, y, ZBOT))
    for i in range(1, resolution + 1):
        a = -math.pi / 2 - math.pi * i / resolution
        pts.append((DRIVE_X + R_END * math.cos(a), y, MID_Z + R_END * math.sin(a)))
    return pts

for lane_i, y in enumerate(YLANES):
    side = "L" if lane_i == 0 else "R"
    v4.tube(f"rope_{side}_endless_loop", rope_loop_points(y), 0.0062,
            material=rope_mats[lane_i], body=frame, cyclic=True)
    # Different fine crown tracer makes both endlessly routed courses readable.
    trace_y = y + (-0.004 if y < 0 else 0.004)
    v4.tube(f"rope_{side}_tracer", [(x, trace_y, z) for x, _, z in rope_loop_points(y)], 0.0012,
            material=rope_traces[lane_i], body=frame, cyclic=True)

# Thin translucent paper tail; its tapered inlet leader narrows into the rope nip.
v4.extrude("paper_tail_tapered_web",
           [(-0.91, ZTOP), (-0.66, ZTOP - 0.021), (0.60, ZTOP - 0.021),
            (0.60, ZTOP + 0.021), (-0.66, ZTOP + 0.021)],
           0.0005, loc=(0, 0.00025, 0), rot=(math.pi / 2, 0, 0),
           bevel=0.00008, material=paper, body=frame)
# Entry and exit edge rollers touch the sheet edge and bear on the inner support rails.
for x, label in ((-0.588, "entry"), (0.588, "exit")):
    v4.cylinder(f"paper_{label}_edge_roller", 0.008, 0.38, (x, 0, MID_Z + 0.005),
                rot=(math.pi / 2, 0, 0), bevel=0.001, material=steel, body=frame)

# Entry/exit comb plates and roller guards with perforated-looking slots.
for x, name in ((-0.84, "entry"),):
    v4.box(f"{name}_guide_plate", (0.025, 0.40, 0.018), (x, 0, MID_Z), bevel=0.004,
           material=aluminum, body=frame)
    for y in (-0.14, -0.07, 0.07, 0.14):
        v4.cylinder(f"{name}_guide_pin_{y:+.2f}", 0.004, 0.014, (x, y, MID_Z + 0.016),
                    bevel=0.0008, material=steel, body=frame)
    for sy in (-1, 1):
        v4.box(f"{name}_comb_mount_{sy}", (0.08, 0.022, 0.022),
               (x * 0.97, sy * 0.1764, MID_Z), bevel=0.002, material=paint, body=frame)
# Removed the former orange top-rail trim; guarded rope courses remain fully visible.

# Drive motor/reducer silhouette at the input end, with cooling ribs and an end cap.
v4.box("motor_foot", (0.23, 0.13, 0.025), (-0.76, -0.245, 0.245), bevel=0.004,
       material=dark_metal, body=frame)
v4.cylinder("motor_can", 0.060, 0.19, (-0.76, -0.245, 0.315), rot=(0, math.pi / 2, 0),
            bevel=0.005, material=paint_dark, body=frame)
v4.cylinder("motor_end_cap", 0.049, 0.012, (-0.86, -0.245, 0.315), rot=(0, math.pi / 2, 0),
            bevel=0.002, material=aluminum, body=frame)
for i in range(8):
    y = -0.245 - 0.045 + i * 0.013
    v4.box(f"motor_cooling_rib_{i}", (0.14, 0.003, 0.008), (-0.76, y, 0.315), bevel=0.001,
           material=steel, body=frame)
v4.box("motor_terminal_box", (0.07, 0.07, 0.05), (-0.75, -0.245, 0.375), bevel=0.006,
       material=paint, body=frame)

# Readable industrial data plate and small engraved labels.
v4.box("nameplate", (0.22, 0.004, 0.075), (-0.24, -0.2695, 0.688), bevel=0.0004,
       material=aluminum, body=frame)
v4.box("nameplate_rule_upper", (0.15, 0.0005, 0.004), (-0.24, -0.2718, 0.704),
       bevel=0.0001, material=ink, body=frame)
v4.box("nameplate_rule_lower", (0.11, 0.0005, 0.003), (-0.24, -0.2718, 0.674),
       bevel=0.0001, material=ink, body=frame)
v4.text("nameplate_title", "PAPER TAIL DRIVE", 0.010,
        loc=(-0.24, -0.2716, 0.694), rot=(math.pi/2, 0, 0),
        extrude_depth=0.0003, material=ink, body=frame)
v4.text("nameplate_spec", "DUAL ROPE / TAKE-UP", 0.0065,
        loc=(-0.24, -0.2716, 0.662), rot=(math.pi/2, 0, 0),
        extrude_depth=0.00025, material=ink, body=frame)
for i, x in enumerate((-0.55, -0.35, -0.15, 0.05, 0.25, 0.45)):
    v4.box(f"travel_scale_tick_{i}", (0.0025, 0.003, 0.018 if i % 2 == 0 else 0.010),
           (x, 0.2675, 0.689), bevel=0.0005, material=ink, body=frame)

# Exporter maps Blender shape names through a punctuation-stripping sanitizer; prefix each
# visible shape with a numeric ID so names such as x=-0.23 and x=+0.23 stay distinct there.
for shape_i, obj in enumerate([o for o in bpy.data.objects if o.type in {"MESH", "CURVE", "FONT"}]):
    obj.name = f"shape{shape_i:04d}_{obj.name}"

v4.save(os.path.join(os.getcwd(), "asset.blend"))
print("saved asset.blend")
