It's cumbersome to test macros, because of having to include them in a menu, compile the menu and make the new version current, etc., so I'm flying by the seat of my pants, but here's my guess:
Help for the (while) function says it returns the last value of the last expression, which in this case would be the (command pause) thing. If you've just finished drawing a Polyline with it, that returned value would probably be Enter. If that's returned, it's probably what is starting up the PLINE command again, and then the PLINEWID would indeed be invalid to answer the first prompt.
One way you might be able to test it, without changing anything yet, would be to use it, and try hitting the *Escape* key to end the Polyline, rather than Enter. Then I'm guessing the (while) function should return a Cancel, the PLINE command should *not* be recalled, and the PLINEWID reset should work.
If that's what happens, try simply forcing a cancel after the (while) function:
(while (> (getvar 'cmdactive) 0) (command pause)) ^CPLINEWID 0
That should allow you to end the Pline with Enter *or* Escape [or even Close], without getting stuck in a new Pline command afterwards.
--
Kent Cooper
Kent Cooper, AIA