Merge pull request #21416 from jffmichi/custom_gcode_allow_empty_lines

CAM: allow empty lines in Custom operation
This commit is contained in:
sliptonic
2025-05-29 09:47:32 -05:00
committed by GitHub
17 changed files with 81 additions and 23 deletions

View File

@@ -344,7 +344,7 @@ def parse(pathobj):
if command == lastcommand:
outstring.pop(0)
if c.Name[0] == "(" and not OUTPUT_COMMENTS: # command is a comment
if c.Name.startswith("(") and not OUTPUT_COMMENTS: # command is a comment
continue
# Now add the remaining parameters in order

View File

@@ -282,7 +282,7 @@ def parse(pathobj):
commandlist = [] # list of elements in the command, code and params.
command = c.Name # command M or G code or comment string
if command[0] == "(":
if command.startswith("("):
command = PostUtils.fcoms(command, COMMENT)
commandlist.append(command)

View File

@@ -394,7 +394,7 @@ def parse(pathobj):
if command == lastcommand:
outstring.pop(0)
if c.Name[0] == "(" and not OUTPUT_COMMENTS: # command is a comment
if c.Name.startswith("(") and not OUTPUT_COMMENTS: # command is a comment
continue
# Now add the remaining parameters in order

View File

@@ -199,9 +199,12 @@ def export(objectslist, filename, argstring):
print("done postprocessing.")
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()
if not filename == "-":
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()
return final
def linenumber():
@@ -251,7 +254,7 @@ def parse(pathobj):
command = c.Name
# fablin does not support parenthesis syntax, so removing that (pocket) in the agnostic gcode
if command[0] == "(":
if command.startswith("("):
if not OUTPUT_COMMENTS:
pass
else:

View File

@@ -408,7 +408,7 @@ def parse(pathobj):
if command == lastcommand:
outstring.pop(0)
if c.Name[0] == "(" and not OUTPUT_COMMENTS: # command is a comment
if c.Name.startswith("(") and not OUTPUT_COMMENTS: # command is a comment
continue
# Now add the remaining parameters in order

View File

@@ -496,7 +496,7 @@ def parse(pathobj):
if command == "G80" and lastcommand == nextcommand:
continue
if c.Name[0] == "(" and not OUTPUT_COMMENTS: # command is a comment
if c.Name.startswith("(") and not OUTPUT_COMMENTS: # command is a comment
continue
# Now add the remaining parameters in order

View File

@@ -313,7 +313,7 @@ def parse(pathobj):
if command == lastcommand:
outstring.pop(0)
if c.Name[0] == "(" and not OUTPUT_COMMENTS: # command is a comment
if c.Name.startswith("(") and not OUTPUT_COMMENTS: # command is a comment
continue
# Now add the remaining parameters in order

View File

@@ -347,7 +347,7 @@ def parse(pathobj):
if command == lastcommand:
outstring.pop(0)
if c.Name[0] == "(" and not OUTPUT_COMMENTS: # command is a comment
if c.Name.startswith("(") and not OUTPUT_COMMENTS: # command is a comment
continue
# Now add the remaining parameters in order

View File

@@ -379,7 +379,7 @@ def parse(pathobj):
if command == lastcommand:
outstring.pop(0)
if c.Name[0] == "(" and not OUTPUT_COMMENTS: # command is a comment
if c.Name.startswith("(") and not OUTPUT_COMMENTS: # command is a comment
continue
# Now add the remaining parameters in order

View File

@@ -359,7 +359,7 @@ def parse(pathobj):
output += scommands[command](c)
if c.Parameters:
CurrentState.update(c.Parameters)
elif command[0] == "(":
elif command.startswith("("):
output += "' " + command + "\n"
else:
print("I don't know what the hell the command: ", end="")

View File

@@ -352,6 +352,7 @@ def linenumberify(GCodeString):
def export(objectslist, filename, argstring):
processArguments(argstring)
global UNITS
global linenr
@@ -412,7 +413,7 @@ def export(objectslist, filename, argstring):
command = command.replace("G0", "G") # normalize: G01 -> G1
if command != UNITS or UNITS_INCLUDED:
if command[0] == "(":
if command.startswith("("):
command = PostUtils.fcoms(command, COMMENT)
# the mapping is done for output only! For internal things we
# still use the old value.
@@ -584,8 +585,16 @@ def export(objectslist, filename, argstring):
lastcommand = c.Name
gcode = gcode.replace("_", "-")
gcode += linenumberify(GCODE_FOOTER)
if SHOW_EDITOR:
PostUtils.editor(gcode)
gfile = pyopen(filename, "w")
gfile.write(gcode)
gfile.close()
# show the gCode result dialog
if FreeCAD.GuiUp and SHOW_EDITOR:
final = PostUtils.editor(gcode)
else:
final = gcode
if not filename == "-":
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()
return final

View File

@@ -602,7 +602,7 @@ def parse(pathobj):
if command == lastcommand:
commandlist.pop(0)
if c.Name[0] == "(" and not OUTPUT_COMMENTS: # command is a comment
if c.Name.startswith("(") and not OUTPUT_COMMENTS: # command is a comment
continue
# Now add the remaining parameters in order

View File

@@ -448,7 +448,7 @@ def parse(pathobj):
if command == lastcommand:
outstring.pop(0)
if command[0] == "(": # command is a comment
if command.startswith("("): # command is a comment
if OUTPUT_COMMENTS: # Edit comment with COMMENT_CHAR
outstring.insert(0, COMMENT_CHAR)
else: