Grasshopper remove line with word from g-code

working in rhino 7

remove line from (9.9 KB)

trying to write a ghpython script to remove any lines with a word in it

What am I doing wrong? … please help

right click on the text input panel and deselect multiline data
rename a to Output

1 Like

Thank you @adel.albloushi, what do I need to do to maintain the multi-line data?

I think it should work.
But you’ll get null/empty outputs which you’d need to cull

Now I’d like to cull the empties from within the script but I get an implicit Grasshopper cycle error

import rhinoscriptsyntax as rs

def remove_word_lines(gcode, word):
lines = gcode.split(‘\n’)
cleaned_lines = [line for line in lines if word not in line and line.strip() != ‘’]
return ‘\n’.join(cleaned_lines)

Input parameters

gcode = Gcode
word_to_remove = WordToRemove

Call the function to remove lines containing the specified word

if gcode is not None and word_to_remove is not None: # Check if inputs are not None
cleaned_gcode = remove_word_lines(gcode, word_to_remove)
cleaned_gcode = “” # Provide default value if inputs are None

Output cleaned G-code

Output = cleaned_gcode

Any idea how to fix it?

Can you upload the gh file itself?

It’s also helpful to have a bunch of typical text you expect to feed into the python component

anyway, here’s the fixed gh
remove line from g-code[fixed].gh (12.1 KB)

@adel.albloushi Thank you!

1 Like