• Login
Community
  • Login

Is it possible to do automatic mathematical operations in specific lines in Notepad++?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
8 Posts 7 Posters 1.5k Views
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.
  • B
    Big Smoke
    last edited by Big Smoke Oct 14, 2023, 3:16 PM Oct 14, 2023, 3:16 PM

    To make it understandable, here’s the exact thing I need and not something general. Here are some lines from a pose file for a posing software:

    head tongue a: 0 0 0 0 0 0 1 1 1
    head tongue b: 0 0 0 0 0 0 1 1 1
    head cheek right 3: 0 0 0 0 0 0 1 1 1
    head cheek left 3: 0 0 0 0 0 0 1 1 1
    arm right shoulder 1: 0 0 0 0 0 0 1 1 1
    arm right shoulder 2: -13 -51 54 0 0 0 1 1 1
    arm right shoulder adj: 0 0 0 0 0 0 1 1 1
    arm right elbow: -18 34 -3 0 0 0 1 1 1

    What I want to be magically done, is recognizing the specific line (the ones containing ‘arm right shoulder 2’ and ‘arm right elbow’ for example) and adding or subtracting from the third numerical value - like changing 54 into 40 and -3 into 12. Is it even technically possible without doing it manually?

    A C M 3 Replies Last reply Oct 14, 2023, 3:22 PM Reply Quote 0
    • A
      Alan Kilborn @Big Smoke
      last edited by Oct 14, 2023, 3:22 PM

      @Big-Smoke

      See https://community.notepad-plus-plus.org/topic/23170/faq-desk-can-i-do-a-mathematical-replacement

      F 1 Reply Last reply Oct 23, 2023, 5:39 PM Reply Quote 0
      • C
        Coises @Big Smoke
        last edited by Coises Oct 14, 2023, 5:31 PM Oct 14, 2023, 5:22 PM

        @Big-Smoke said in Is it possible to do automatic mathematical operations in specific lines in Notepad++?:

        To make it understandable, here’s the exact thing I need and not something general. Here are some lines from a pose file for a posing software:

        head tongue a: 0 0 0 0 0 0 1 1 1
        head tongue b: 0 0 0 0 0 0 1 1 1
        head cheek right 3: 0 0 0 0 0 0 1 1 1
        head cheek left 3: 0 0 0 0 0 0 1 1 1
        arm right shoulder 1: 0 0 0 0 0 0 1 1 1
        arm right shoulder 2: -13 -51 54 0 0 0 1 1 1
        arm right shoulder adj: 0 0 0 0 0 0 1 1 1
        arm right elbow: -18 34 -3 0 0 0 1 1 1

        What I want to be magically done, is recognizing the specific line (the ones containing ‘arm right shoulder 2’ and ‘arm right elbow’ for example) and adding or subtracting from the third numerical value - like changing 54 into 40 and -3 into 12. Is it even technically possible without doing it manually?

        My plugin Columns++ can do this. This plugin is still in development. It is not offered through the plugins manager, but there is a quick installer at the link I gave. While I believe it is already useful and reasonably stable, odd behavior shouldn’t yet be considered unlikely, so be sure to have a safe copy of your data! There is a help file.

        Note: If you need to make many sets of changes, and this is something you’ll want to do often, a scripting solution would be better. If this is a one-time thing (or at least an unusual thing) and you want to try a new plugin, read on.

        For this task, after installing Columns++, you would first select the entire document, then choose Search… from the Columns++ menu and enter:

        Find what : (arm right shoulder 2:\h*([\-\d]+\h+){2})([\-\d]+)
        Replace with : $1(?=reg(3)-14)

        Make sure that Regular expression is selected as the Search Mode and use either Replace repeatedly to find and change each occurrence, or Replace All to do them all at once.

        Change the Find what text after the first parenthesis up to the colon to change what line you search; change the number in the {2} to change how many numbers you skip before the number you want to change; change the formula after the equal sign in Replace with to change the calculation. The reg(3) refers to the third capture group in the find expression — it doesn’t mean the “third number,” so don’t change it when you change {2}. You can’t specify {0}, though, so if you need to replace the first number, remove the entire ([\-\d]+\h+){2} and change reg(3) to reg(2).

        1 Reply Last reply Reply Quote 2
        • M
          mkupper @Big Smoke
          last edited by mkupper Oct 14, 2023, 6:37 PM Oct 14, 2023, 5:52 PM

          @Big-Smoke said in Is it possible to do automatic mathematical operations in specific lines in Notepad++?:

          Is it even technically possible without doing it manually?

          I usually deal with things like that by first using regular expressions to normalize the data into a format that is easy to then copy/paste or import into something else, usually a spreadsheet, that does the math.

          Your data for example is space delimited after the colon. A regular expression to make those tabs is
          Search: (?<=[0-9:])\x20+(?=[0-9-])
          Replace: \t

          The search part looks for one or more spaces (the \x20+ part) that is preceded by either a digit or colon (the (?<=[0-9:]) part) and is followed by a digit or minus sign (the (?=[0-9-]) part). The spaces are replaced by a tab.

          At that point it’s easy to copy/paste the block of lines into Excel and to add spreadsheet columns that do your math.

          Thus it’s semi manual. If you needed to do this dozens or more times then are ways to automate the process but much of that would be outside the scope of Notepad++ which is the focus of this Internet forum.

          Edit: a minor tweak is to search for (?<=[0-9:])\x20+ as we don’t need the (?=[0-9-]) part. The shorter version looks for a digit or colon followed by one or more spaces. You still replace it with a \t tab. The shorter version will put a tab at the end of the line if there are spaces after the last number in a line.

          1 Reply Last reply Reply Quote 2
          • F
            freezer2022 @Alan Kilborn
            last edited by freezer2022 Oct 23, 2023, 5:44 PM Oct 23, 2023, 5:39 PM

            @ Big smoke said : Is it possible to do automatic mathematical operations in specific lines in Notepad++?

            @ Alan-Kilborn said : See

            https://community.notepad-plus-plus.org/topic/23170/faq-desk-can-i-do-a-mathematical-replacement
            

            Maybe in that FAQ, apart of Columns++ plugin, it’s worth to mention another 2 math related plugins: Expression calculator and NppCalc :

            1) https://planet-cnc.com/notepad-plugin/
            2) https://sourceforge.net/projects/nppcalc/
            
            P T 2 Replies Last reply Oct 23, 2023, 6:32 PM Reply Quote 0
            • P
              PeterJones @freezer2022
              last edited by PeterJones Oct 23, 2023, 6:58 PM Oct 23, 2023, 6:32 PM

              @freezer2022 ,

              1. https://planet-cnc.com/notepad-plugin/
              2. https://sourceforge.net/projects/nppcalc/

              Those plugins don’t seem to help this particular topic, since the original post indicated they wanted the correct lines automatically found (“recognizing the specific line”), extracting certain pieces out of that line (“adding or subtracting from the third numerical value”) and running math operations that weren’t specified in the original text. As far as I can tell, both of the plugins you mention require knowing where the numbers are that you want operated on, and typing the formulas in the syntax of that plugin in the text to make use of those numbers – and if the numbers have to already be in the right spots in the formulas, it doesn’t help in this topic.

              I’ll respond to your suggestion elsewhere (link will be inserted soon)

              -----
              update: New Topic: Math and Notepad++. Please move any Math-and-Notepad++discussion that’s not relevant to @Big-Smoke’s original question into that new topic.

              F 1 Reply Last reply Oct 24, 2023, 10:18 AM Reply Quote 0
              • T
                Thomas Knoefel @freezer2022
                last edited by Thomas Knoefel Oct 23, 2023, 8:27 PM Oct 23, 2023, 6:44 PM

                @freezer2022
                I can provide you with an additional solution using the MultiReplace Plugin available in the upcoming Notepad++ version 8.5.8.
                This gives you one more option to choose from, on top of the already shared solutions ;-)

                Find what: (arm right shoulder 2: -?\d+ -?\d+)(\s)(-?\d+)
                Replace with: set("$1 "..(CAP3 - 14))

                activate Options:
                -Use Variables
                -Regex

                `

                1 Reply Last reply Reply Quote 1
                • F
                  freezer2022 @PeterJones
                  last edited by freezer2022 Oct 24, 2023, 11:15 AM Oct 24, 2023, 10:18 AM

                  @PeterJones : Those plugins (…)
                  @Thomas-Knoefel

                  OK, good to know, I asked because I’m not a mathematician, nor have I ever used any math plugins, but it’s always worth mentioning plugins even if they turn out to be not much helpful, than not mentioning and later they turn out to be useful and no one knew/mentioned about it.

                  @PeterJones : Please move any Math-and-Notepad++discussion that’s not relevant to @ Big-Smoke’s original question into that new topic.

                  Besides, also I didn’t want to create a separate thread because I only wanted to post a single comment, not to create a discussion and not to litter the forum with unnecessary threads, also like I said - I don’t use math plug-ins anyway, hence I won’t participate in the discussion.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors