As you observed, when you run PTGen from a SamUL script using the PtOptimize() function, the Command window takes focus for the few seconds that PTGen is running and displays itself on top of other windows that are open on your desktop.
That can be annoying if your script takes a long time to run and you want to use other programs on your computer while it is running.
For now, there is not a way to change this behavior.