Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

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

    Help wanted · · · – – – · · ·
    2
    3
    266
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Bob Thebuilder
      Bob Thebuilder last edited by

      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?

      Alan Kilborn 1 Reply Last reply Reply Quote 0
      • Alan Kilborn
        Alan Kilborn @Bob Thebuilder last edited by Alan Kilborn

        @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.

        Bob Thebuilder 1 Reply Last reply Reply Quote 2
        • Bob Thebuilder
          Bob Thebuilder @Alan Kilborn last edited by

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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Copyright © 2014 NodeBB Forums | Contributors