Creating new wall type using pyRevit (python3)

Hi there,
Im trying to create a new wall type in Revit. I first clone an existing wall type and than i am modifying the layers (e.g. thickness) of the layers. But somehow Im not able to change the actual
thickness. It will create a new wall type though, but its just the same as the base object.

thanks a lot! Matthias


    wall_types = list(FilteredElementCollector(doc).OfClass(WallType).ToElements())
    base_type = next((wt for wt in wall_types if wt.Name == base_type_name), None)

    # --- Start Transaction ---
    t = Transaction(doc, f"Create Wall Type: {new_type_name}")
    try:
        t.Start()

        # Delete existing wall type with same name
        existing = next((wt for wt in wall_types if wt.Name == new_type_name), None)
        if existing:
            doc.Delete(existing.Id)
            output.print_md(f"Deleted existing wall type: `{new_type_name}`")

        # Duplicate the base wall type
        new_type = base_type.Duplicate(new_type_name)
        if not new_type:
            raise Exception("WallType.Duplicate() returned None")

        # Get compound structure (cannot create from scratch)
        cs = new_type.GetCompoundStructure()
        if cs is None:
            raise Exception("Base wall type has no compound structure.")

        # Modify structure layer
        thickness_ft = meters_to_feet(core_thickness_mm / 1000.0)
        layers = list(cs.GetLayers())

        # Modify structure layer directly
        modified = False
        print("layers: ", len(layers))
        for i, layer in enumerate(layers):
            # if layer.Function == MaterialFunctionAssignment.Structure:
            layer.Width = core_thickness_mm
            output.print_md(f"Modified layer {i} to {thickness_ft} ft")
            layers[i] = layer
            output.print_md(f"Updated layer {i} to {layer.Width} ft")

            modified = True
            output.print_md(
                f"Modified structure layer at index {i} to {core_thickness_mm} mm"
            )

        if not modified:
            raise Exception("No structure layer found in base wall type.")

        cs.SetLayers(layers)

        t.Commit()
        output.print_md(f"Created new wall type: `{new_type_name}`")
        return new_type