How do I copy an image from the reference line to a new layer?

In an image, I have drawn reference lines using a newly created reference line layout, including both horizontal and vertical lines. How can I use a script to copy the images from these reference lines to a new layer? I have manually operated this in the image, and I understand the basic principle, but I'm unsure how to write it. My idea is to first obtain the coordinates of the reference lines, then check for the existence of either vertical or horizontal reference lines, and finally copy the images from the reference lines to a new layer. Thank you all for your help.
