Add the same amount to every selected value?
-
@diz-hydron said in Add the same amount to every selected value?:
I’m not a programmer
Alas the only way to do this in Notepad++ is via programming.
There are a lot of forum postings about this topic; perhaps a good one to have a look at is HERE.
-
Hmm. Unfortunate.
It looks like what you’ve listed replaces a predetermined value that’s been manually defined. Idk if that value is automatically set to display the value selected, but at least in my ignorance it still looks like I’d need to input each value manually into the program.
Does anyone know of any other tool like Notepad ++ that might do the trick? I still find Notepad ++ to be really useful, but I’d still like to save time if possible.
-
Ok, so maybe I misinterpreted your original posting. I now notice that you’ve said:
I’ve figured out how to use multi-edit to select multiple values
These postings usually go where someone gets a selection via a “find” operation. That’s what my solution suggestion was geared for.
And if you could come up with an appropriate “find” expression to match the data that you’ve manually selected, you can use my suggested solution (it’s just a matter of changing “plus 1” in the example to the “plus 200” that you need – an easy change).
-
Ok, it sounds like it is possible then. That being said, I’m still a total programming noob. This program looks simple enough though. It sounds like I’d need to add a function that defines the values based on what I’ve selected and that said function is missing from the example you gave me. Nor do I know how to even start looking for how to write such a function. On top of that, I have no idea how to run a program like this or make it work with Notepad ++.
I’d appreciate some advice on that front if you would be willing to provide some assistance.
-
@diz-hydron said in Add the same amount to every selected value?:
I have no idea how to run a program like this or make it work with Notepad ++.
I’d appreciate some advice on that front if you would be willing to provide some assistance.Fortunately, I recently wrote a generic set of instructions for how to install the plugin and use it to run scripts like the one Alan linked you to: see the new FAQ entry
-
Thanks!
I’ll take a look and see if I can figure this out. I’ll come back if I have any questions.
-
Ok, Everything is installed and I’ve created the new script. The problem now is the script itself.
From what I can tell with my limited knowledge of programming, this is pretty simple. The first line defines the change to be made. No clue what the second line does, 4-7 are comments, and line 9 applies the change to any value that matches the value in the parentheses. In this case, ‘X([0-9]+)’
I’m guessing that this value can be changed to any other value manually.
It sounded like Alen was saying there’s a “find” operation that will replace this value with whatever is currently highlighted. I’d assume that it would also be able to use multiple different values as well. In other words, this needs a line that defines what is to be the subject of the change be defined as all values highlighted. As to what that operation is, I have no idea. Didn’t see anything like that in the FAQ linked by PeterJonez.
I think this is where I get stuck. Anyone know what I need to do next?
-
So the script acts on something that is “found”, not something that is “selected”. Unfortunately, you didn’t show enough of your sample data for us to give you any help on writing a find expression for it, but the hint of what you gave seems to have something of a pattern to it (which it would need, to be findable).
If you’re still having trouble seeing this, try seeing what the sample script does when you run it; or read the comments in the script.
-
Hi! Thanks for getting back to me!
I’m having a little bit of trouble understanding what you’re saying, but I think I get the gist. If it finds values instead of selecting them then I’m not too sure it would work. I have a lot of values and many of them are the same, but I need to be specific about which change. Here’s a bit more of what I’m working with.
What I’m trying to do is to quickly be able to change every X or Y value for player 1 or 2 by a set amount and speed up the workflow.
the values after player 1 and 2 define X and Y values. If I told the program to find every instance of 15 and add 100 for example, then it would presumably change the values for player 1 and 2. I could try and define it as “player1”: [ then the value afterward, but I’d need to type that out for every value I’d want to change and that takes as much work, if not more than just changing them manually. Unless there’s some way to define a chunk of characters as a variable. For example, “player1”: [X where X = every character prior to the , that separates the X from Y co-ordinate. Y may be possible too if I can exclude chunks of characters as in “player1”: [X, Y where X is any characters between [ and , and Y is the value to be changed.
I don’t even know if groupings of characters is definable in python. I just said it because I could see things getting complicated with double/triple-digit and negative numbers. From what you’re saying though it sounds like I’d need to manually put in “player1”: [ for every player 1 X value in order to get this mehtod to work. At that point, it’s slower than just adding a set amount to each value manually.
-
If you search for this, you’ll see it only hits player1 values:
Find:
"player1": \\[\K-?\d+
Search mode: Regular expressionThat might be the key to understanding enough for the scripted solution shown above to do the job for you.
-
I don’t know how to properly implement the string you provided, but I gave it a shot. Didn’t do anything when I ran the script.
Here’s what I have. I’m guessing I need to do something in line 3.
-
@diz-hydron Alan’s intention was that you revise the search criteria in the editor.rereplace function call (which identifies every instance of the targeted numeric fields to undergo the math operation and replacement).
In other words, go back to the original script you showed (after “Ok, Everything is installed…”) and replace line 9 with
editor.rereplace('"player1": \[\K-?\d+')
Didn’t see anything like that in the FAQ linked by PeterJonez.
Although he is a rapper by night, in this forum we try to stick with his daytime persona, that of a software professional.
-
Is this correct? Still doesn’t seem to be doing anything when I try to run it. Then again, maybe my attempts at running it/defining the values are the problem. I know nothing about python.
Also, my apologies for the typo. It was not intentional, nor was it my intention to offend.
-
@diz-hydron Let’s just first verify core functionality by asking the script to do something very simple: use
'47'
inside the parentheses, and see if the 47 for player1 under singRIGHT line undergoes the change.Also, it’s much preferred that you place your scripts in
a literal text box like this
using lines with triple backquotes as explained here; look for Literal Text Blocks and Red Typewriter Text. It’s preferred over images because it enables text copying while also protecting against being altered by this forum’s software.
Also, my apologies for the typo. It was not intentional, nor was it my intention to offend.
I was only being silly. Some typos are too delicious to pass over without comment.
-
@diz-hydron Also, if you want to apologize for a typo, here’s a much better candidate: in your prior attempt, the (much needed) backslash before the left brace is missing.
-
@neil-schipper said in Add the same amount to every selected value?:
while also protecting against being altered by this forum’s software
Yeah, annoyingly and amusingly, there’s a flaw in that text box rendering code, and it impacts text that’s part of this discussion:
unfortunately, <backslash><left brace> renders as: \[ so you need <backslash><backslash><left brace> in order to make this appear: \\[
-
@neil-schipper said in Add the same amount to every selected value?:
In other words, go back to the original script you showed (after “Ok, Everything is installed…”) and replace line 9 with editor.rereplace(‘“player1”: [\K-?\d+’)
Oh, heck, it was me that introduced the dropped backslash…
editor.rereplace('"player1": \\[\K-?\d+')
-
@neil-schipper said in Add the same amount to every selected value?:
editor.rereplace(‘“player1”: \[\K-?\d+’)
Because it includes backslashes, probably want this instead:
editor.rereplace(r'"player1": \\[\K-?\d+')
(note the leading
r
) -
I appreciate all the help! I’ll need to get to this a bit later though. Busy day today.
In the meantime, I’d like to make sure that I’m not trying to drive the car without the key and make sure I understand how to run a plugin in the first place.
First, I go plugins/python script/new script. Then, I populate the file with the script I want to run and save it to the scripts folder. Finally, I open the text that I want the script to change, use a shortcut key as described in the FAQ, or run it by selecting plugins/python script/scripts/“Custom Script” Then if the script works, it should apply the change.
Is my understanding of that part correct? I can take a closer look at fixing the script itself a bit later.
-
@diz-hydron said in Add the same amount to every selected value?:
Is my understanding of that part correct?
Sounds right, although for sure don’t bother with the shortcut key thing right out of the box. That would only be useful if this whole thing actually works for you, and if you need to do it multiple times. Just run the script from the menus to start with.