This is something the couple should discuss with a good Catholic doctor, like those at the Pope Paul VI Institute.
There are licit means of obtaining semen, one is the couple has intercourse and he wears a perforated condom. Another is the semen is collected with a needle directly from the body.
As has been said, a perforated condom defeats the purpose of isolating the semen from the woman’s immune system. The other method you mentioned is quite possible, and I commend you on the diplomatic way you described it.

OUCH!
Additionally, a tiny electric shock administered a few inches inside the rectum will cause spontaneous and involuntary ejaculation. That may also be a licit method, I am not sure.
This method is called “electroejaculation”, and from what I’ve heard is not terribly pleasant. It is fairly routinely used to collect semen from bulls and boars for artificial insemination.
Good question as to whether or not it’s a licit method of obtaining a sample. In either case, masturbation or electroejaculation the intent is to obtain a semen sample, not for pleasure. It seems to me that it’s not the ***method ***that’s morally in question, but the
intent, since in either case the result is ejaculation/orgasm.
Perhaps the counter argument is that the end does not justify the means. However, going through electroejaculation does have certain risks, whereas masturbation does not. I would have a difficult time believing that a man masturbating to obtain a semen sample for such a reason would get any real pleasure out of it, given the gravity of his wife’s condition.
That has never happened to me. Not even when I was younger. Personally, I think it is a myth. Or perhaps an excuse.
A myth? No, and not an excuse either. It happens.