Community
    • Login

    renumbering/incremental

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    45 Posts 7 Posters 6.8k 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.
    • Scott RaskinS
      Scott Raskin @Scott Raskin
      last edited by

      @Alan-Kilborn Sorry for breaking this into two messages: I also see where you have the self.search_regex and def retuen_replacement_text_func(m) I would be l;looking to make any future code modifications, so I can probably try adding that \A(?-s).\R.\R.\R.\R.\R.\R.*\R into the first part and the replacement into the second I just dont want to screw up the code. I will be back at the factory in a few hours to see.
      Thanks again

      1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Scott Raskin
        last edited by Alan Kilborn

        @Scott-Raskin said in renumbering/incremental:

        First thing I noticed was I needed to change this line: renumbering = [ 1, 1 ] to renumbering = [ 10, 1 ], as it has to start at 10

        You could change it the way you state, but I’d suggest this as cleaner:

        renumbering[CURRENT] = 10
        

        inserted above this line in the script:

        renumbering[INCREMENT] = 10
        

        The “current” value is the starting value, and also the “running” value as the replacement moves along (that’s why I didn’t want to call it “starting”). Expressing one’s self in code isn’t always straightforward.

        The “increment” value is well-named, but the fact that the INCREMENT tag in the code is 1 and NEVER should be changed, well, this does seem odd (it is used for a different purpose than one might think). Expressing one’s self in code isn’t always straightforward.

        If you just think in terms of:

        • if I want to change the starting value, I need to set renumbering[CURRENT] = something

        • if I want to change the incrementing value, I need to set renumbering[INCREMENT] = something

        and forget about the rest…for this specific application.


        This is all amazing, and even with you being modest, you still put a good deal of effort into this and it is much appreciated

        Not a problem. Part of the goal was somewhat of a generic solution (as you’ve probably noticed), so that the next time a question like this comes up (and it will), there is a model of a solution for it.

        1 Reply Last reply Reply Quote 1
        • Alan KilbornA
          Alan Kilborn @Scott Raskin
          last edited by Alan Kilborn

          @Scott-Raskin said :

          …run your script, followed by that search/replace it seems it does all I need to do.

          Its only 2 operations if I need to do separately and it will change 10k files so its worth it either way

          The script is rather dedicated to its renumbering/incrementing purpose, but it is just code so you could change it to go beyond that.

          As the search/replace op you mention is just a normal one (no special math/renumber/increment stuff), you could just include an editor.rereplace(search,replace) function call right after this line:

          replacements_made_in_this_file = self.perform_custom_replace_in_one_file(first_time_thru)
          

          Note however that this would invalidate the script’s results reporting (at completion, telling you number of replacements made, etc.). Not a big deal if you trust the script, mainly I put that stuff in to be general purpose, and to give a user a sanity check if they know about how many files should be matched via filespec/filter, about how many replaces should have been done, etc.

          If I were you, I’d keep it as two separate and distinct operations, running of a script, and then a follow-up Replace in Files op.

          Scott Raskin 0S 1 Reply Last reply Reply Quote 1
          • Scott Raskin 0S
            Scott Raskin 0 @Alan Kilborn
            last edited by

            @Alan-Kilborn tried this
            self.print(‘making replacements in’, pathname)
            replacements_made_in_this_file = self.perform_custom_replace_in_one_file(first_time_thru)
            editor.rereplace(\A(?-s).\R.&\R.\R.\R.\R.\R.\R.*\R,O0001 ;N0001 ;N0002 ;N0003 ;N0005 G94 G53 G56 T0000 ;N0010 G92 X0.6820 Z2.1505 ;
            ) self.print(‘{} replacements made in current file’.format(replacements_made_in_this_file))

            and the script wont even run now. Maybe youre right and 2 ops is the best

            Scott RaskinS Alan KilbornA 2 Replies Last reply Reply Quote 0
            • Scott RaskinS
              Scott Raskin @Scott Raskin 0
              last edited by

              @Alan-Kilborn copy/paste made it look weird for some reason in the post but that search/replace was all one line in the script

              Alan KilbornA 2 Replies Last reply Reply Quote 0
              • Alan KilbornA
                Alan Kilborn @Scott Raskin
                last edited by Alan Kilborn

                @Scott-Raskin said in renumbering/incremental:

                copy/paste made it look weird for some reason in the post

                If you want it to appear verbatim in a posting, you have to format it correctly.

                Add lines with 3 backticks at the start and bottom of your “block”:

                ```
                one
                two
                three
                ```

                Do that and it will appear like this:

                one
                two
                three
                

                Alternatively, select the text to format and press the “code” button in the “toolbar” to get the same effect:

                3b9761d1-033d-44e5-a085-6496b5910c8b-image.png

                More info on FORMATTING posts is in the FAQ entry concerning it.

                1 Reply Last reply Reply Quote 0
                • Alan KilbornA
                  Alan Kilborn @Scott Raskin 0
                  last edited by

                  @Scott-Raskin-0

                  Concerning:

                  Maybe youre right and 2 ops is the best

                  I think so…especially due to your newness to the scripting world. As you’ve found, it is very easy to screw up something to the point where a previously-running script now won’t run. (This is often even easy for scripting veterans to do.)

                  1 Reply Last reply Reply Quote 1
                  • Alan KilbornA
                    Alan Kilborn @Scott Raskin
                    last edited by

                    @Scott-Raskin

                    Are you making a “macro” out of your second op, the standard Replace in Files operation?

                    If so, then it really becomes less painful as a separate operation; you don’t have to fill in all the fields in the UI each time, you just pick the “macro” from the Macro menu to run it.

                    So your workflow becomes:

                    • run the script
                    • run the macro

                    Downside of a macro: For a Replace in Files macro, the folder is “hardcoded”.

                    Scott Raskin 0S 1 Reply Last reply Reply Quote 1
                    • Scott Raskin 0S
                      Scott Raskin 0 @Alan Kilborn
                      last edited by

                      @Alan-Kilborn so sorry, we were closed for a bit and Im just getting back. I will try those both this week, thank you so much for all of your help!

                      1 Reply Last reply Reply Quote 1
                      • Alan KilbornA
                        Alan Kilborn
                        last edited by

                        If you’ve used a script in this thread, you might want to double check your copy of it for a bug I’ve discovered.
                        Look to previous postings in this topic thread where the script has been changed – find the text moderator edit (2024-Jan-14).
                        There’s a link there that describes the bug in more detail, and shows what needs to be changed in an old copy (or you can simply grab a copy of the current version).

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