Ground line from linked file

Hi, i made this script to get existing ground lines. When i use a linked topo on this project, the height of topo line created comes out incorrect. I assume its something to do with shared coordinates. Anyone know if there would be a fix for this?