"My name is not Hans, but Karl!"
Translation:Ich heiße nicht Hans, sondern Karl!
Good question! "Heißen" is tricky to negate here. In this case, "heißen" is acting closer to verbs like "sein", where both the subject is the object, instead of doing something to the object, so the object keeps the nominative case. These verbs are called copula verbs.
The way I imagine it is that when you negate copula verbs like "sein" and this use of "heißen", you can't negate the action of "being", so you have to negate the object instead.
From my understanding "sondern" is used in the context of:
"Not this but rather that" or "Not red but rather blue"
And "aber" is used when you are expanding on the sentence rather than giving an alternative:
"Not red but it's a pretty color"
"Mein Name ist nicht Hans, aber Karl" sounds like you're about to expound on the sentence by adding a new clause with Karl as the subject. E.g. "My name is not Hans, but Karl... keeps calling me by that name." On the other hand, "sondern" signifies that you are replacing one thing with another. "My name is not Hans, BUT RATHER Karl."
Can someone help understand what is the rule with respect to placement of Nicht. Another comments thread mentioned the 'nicht' comes right after ist, or bist or sind if they are part of the sentence but other places, it is recommended to have the nicht at the end. It had worked fir me until now. I assume my understanding was not right.