Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-write of Search and Replace #19796

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

GregValiant
Copy link
Collaborator

Added some options:

  • Replace only the 'First Instance' of the Search term.
  • Limit the Search to a layer range.
  • 'Ignore StartUp G-code'
  • 'Ignore Ending G-code'

Description

Added flexibility to the script. The options still allow a full Search and Replace as well as a limited Search and Replace.

Type of change

  • [ X] New feature (non-breaking change which adds functionality)

How Has This Been Tested?

I have been using this version for a year with multiple Cura versions.

Test Configuration:
Win10 Pro on a laptop.
UM Cura 4.13.1 to 5.9beta.

Checklist:

  • [ X] My code follows the style guidelines of this project as described in UltiMaker Meta and Cura QML best practices
  • [ X] I have read the Contribution guide
  • [ X] I have commented my code, particularly in hard-to-understand areas
  • [ X] I have uploaded any files required to test this change

Added some options:
- Replace the 'First Instance Only' of the Search term.
- Limit the Search to a layer range.
- 'Ignore StartUp G-code' and 'Ignore Ending G-code'
@github-actions github-actions bot added the PR: Community Contribution 👑 Community Contribution PR's label Oct 23, 2024
@GregValiant GregValiant added the PR: Post Processing ➕ Like adding beeps, more tunability or different Gcode pause at heights label Oct 23, 2024
@wawanbreton
Copy link
Contributor

Thanks, we will take a look when we are not overbusy 😊
For internal reference: CURA-12325

Update a description

Update SearchAndReplace.py

Fixed the "descriptions".  Cura didn't like the dashes or backslashes.
Copy link
Contributor

github-actions bot commented Jan 7, 2025

Test Results

23 370 tests  ±0   23 368 ✅ ±0   53s ⏱️ -1s
     1 suites ±0        2 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit be509b6. ± Comparison against base commit 382b98e.

♻️ This comment has been updated with latest results.

}
}
}"""

def execute(self, data):
curaApp = Application.getInstance().getGlobalContainerStack()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style: cura_app instead of curaApp.
Or better, since you are actually getting the global container stack: global_stack


for layer_number, layer in enumerate(data):
data[layer_number] = re.sub(search_regex, replace_string, layer) #Replace all.
#Find the raft and layer:0 indexes--------------------------------------------------------------------------
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange comment style. Please use the same style of comments as the rest of Cura.
I am somewhat surprised Python does not complain about the indentation; strictly speaking this indentation ends the previous codeblock.

replaceone = True
break
if replaceone: break
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see, this condition is never met because we're already broken out of the for loop. As a matter of fact, it seems to me that the whole replaceone variable is useless.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that was vestigial code. There may have been a second "for" in there and I used the second 'break' to back all the way out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@fieldOfView
Copy link
Collaborator

There seems to be a lot of unnecessary code duplication after line 170

Update SearchAndReplace.py

Changed comments.
Revised code below line 170.
Changed 'curaApp' to 'cura_app'
@GregValiant
Copy link
Collaborator Author

Thanks @fieldOfView.
I must have missed the first few suggestions. The latest commit addresses the issues from line 170. I'll look at the others here in a minute.

A quick squash and all the changes are in that last commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Community Contribution 👑 Community Contribution PR's PR: Post Processing ➕ Like adding beeps, more tunability or different Gcode pause at heights
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants