Thank you for trying to help me.
I got the program to work, I did not solve the problem, but rather adapted the program to it.
If the program did not find the viewport xref on the first attempt then it will change the viewport scale so that more of the xref is in the ssget "c" 's window, then find the xref, then change the scale back.