I suspect you need to do an Update() before you set TotalSpan.
TotalSpan (and related parms) work by scaling all of a wing's Parms by the ratio of the last Span to the desired Span. However, if you've changed a bunch of Parms -- meaning the stored Span is out of date -- then it will use the wrong scale factor.
Multi section wings can be a real hassle to update from the API. There are two reasons. One is that you have the option to choose the driver groups for each wing section (AR, span, area, taper, cr, ct, cave, secsw) and the second is that depending on those settings, changing a wing section's parameters can actually change the prior or next wing section. I.e. the root chord of a section is the tip chord of the prior section -- and the tip chord is the root chord of the next section.
When using the API, it is generally best to use root chord, tip chord, span as your driver variables and to move from root to tip when setting the chords.
Rob