How to select a line of text, then copy that selected line of text using the pythonscript plugin?



  • I’m trying to figure out how to select a line of text, then copy that selected line of text using the pythonscript plugin. For example, say I want to copy line 11. I want to select line 11, then copy line 11. It seems simple, but I kept getting error after error, and I couldn’t find any resources online that could tell me what to do. I’m trying to open the document, select a line, and use editor.copy() and editor.paste() to put into the document. Does someone else know how to do this?



  • @Bob-Thebuilder

    notepad.open(r'c:\pathtoyourfile\yourfile.txt')
    editor.copyText(editor.getLine(10))
    

    You have to use 10 for line 11 because in code lines are numbered starting with zero, not 1.

    Also, you don’t have to select the line; you can…but you don’t have to. If you select the line using editor.setSelection(..., ...) you can follow that with editor.copy() as that function copies what is selected. But, if you know you want line 11, it is easy to grab line 11 with code rather than making a selection of it.

    but I kept getting error after error

    For us to give you REALLY GOOD help, it would have been better to show your code and the errors you were getting. Otherwise, we can only guess at things, and the tolerance for guessing games is fairly low.



  • @Alan-Kilborn Thanks! This is exactly what I needed!


Log in to reply