It is a test, as far as I'm concerned, for the capabilities of AI.
However, although it has produced a batch file that almost does the job,
it does not seem capable of going the final mile, so to speak. When you
sort of get down into the weeds, it says it understands what it has done
wrong, says that the following script corrects the error, but then the
script is a repeat of the previous one. I'm not sure whether to push it
further. It is relatively trivial for me to write a bit of c++/whatever,
to solve this task, but trying to get the AI to do it is my current
interest. Maybe it is better at Python.
On 28/05/2023 15:07, William F. Adams wrote:
Neat that you're making progress on this!
I approached it from a rather different perspective and instead used
RapCAD for G-code generation:
https://github.com/WillAdams/gcodepreview
I've been documenting it at:
https://willadams.gitbook.io/design-into-3d/programming#gcodepreview
and have been using it inside OpenSCAD Graph Editor:
https://github.com/derkork/openscad-graph-editor
William
-----Original Message-----
From: Ray West raywest@raywest.com
To: OpenSCAD general discussion Discuss@lists.openscad.org
Sent: Sun, May 28, 2023 9:09 am
Subject: [OpenSCAD] OT openai/batch file/svg parse/gcode generate
I thought there may be some interest in how it was proceeding, following
on from a previous thread.
On 25/05/2023 19:14, Raymond West wrote:
You're dead right there, wrt Bing. I'm getting it to write a pretty
comprehensive batch file, to process an openscad svg and generate a
specific version of g-code. It started off by saying it couldn't parse
a file, but it lied. It is taking a while, as I test each iteration,
but it will get there. The result will have plenty of room for
improvement, but It will work good enough.
On 25/05/2023 12:43, nop head wrote:
I use the version built into Bing, which is ChatGPT4 I believe and it
is much better.
So far, managed to generate code to batch process an scad file, doing
various sections, and combining the SVG files. It is struggling with
converting the SVG to g code.
I've patiently gone through 33 iterations of trying the batch file
script generated by the AI (within Bing), and feeding back the errors or
results. It eventually seems to get into a loop, repeating previous
guesses.
This is the input file (just one line)
M 10,-10 L 60,-10 L 60,-60 L 10,-60 z
The output that I want which should be
G01 Z-5
G01 X10 Y10
G01 X60 Y10
G01 X60 Y60
G01 X10 Y60
G00 Z2
I think the closest it has got is the following batch file
@echo off
setlocal enabledelayedexpansion
set "inputFile=input.txt"
set "outputFile=output.txt"
if exist "%outputFile%" del "%outputFile%"
for /f "usebackq delims=" %%a in ("%inputFile%") do (
set "line=%%a"
set "firstM=1"
for %%b in (!line!) do (
if "%%b" == "M" (
if "!firstM!" == "1" (
echo G01 Z-5 >> "%outputFile%"
set "firstM=0"
)
set coord=
) else if "%%b" == "L" (
echo !coord! >> "%outputFile%"
set coord=
) else if "%%b" == "z" (
echo !coord! >> "%outputFile%"
echo G00 Z2 >> "%outputFile%"
) else (
for /f "tokens=1,2 delims=," %%x in ("%%b") do (
set y=%%y
set /a y=-1*!y!
if not defined coord (
set coord=G01 X%%x Y!y!
)
)
)
)
if defined coord echo !coord! >> "%outputFile%"
)
endlocal
it does not show the Y values, although in earlier attempts it did, but
produced other errors.
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
I write as little as possible in batch files. Python is a much better
language and works on all platforms.
On Mon, 29 May 2023 at 12:03, Raymond West raywest@raywest.com wrote:
It is a test, as far as I'm concerned, for the capabilities of AI.
However, although it has produced a batch file that almost does the job, it
does not seem capable of going the final mile, so to speak. When you sort
of get down into the weeds, it says it understands what it has done wrong,
says that the following script corrects the error, but then the script is a
repeat of the previous one. I'm not sure whether to push it further. It is
relatively trivial for me to write a bit of c++/whatever, to solve this
task, but trying to get the AI to do it is my current interest. Maybe it is
better at Python.
On 28/05/2023 15:07, William F. Adams wrote:
Neat that you're making progress on this!
I approached it from a rather different perspective and instead used
RapCAD for G-code generation:
https://github.com/WillAdams/gcodepreview
I've been documenting it at:
https://willadams.gitbook.io/design-into-3d/programming#gcodepreview
and have been using it inside OpenSCAD Graph Editor:
https://github.com/derkork/openscad-graph-editor
William
-----Original Message-----
From: Ray West raywest@raywest.com raywest@raywest.com
To: OpenSCAD general discussion Discuss@lists.openscad.org
Discuss@lists.openscad.org
Sent: Sun, May 28, 2023 9:09 am
Subject: [OpenSCAD] OT openai/batch file/svg parse/gcode generate
I thought there may be some interest in how it was proceeding, following
on from a previous thread.
On 25/05/2023 19:14, Raymond West wrote:
You're dead right there, wrt Bing. I'm getting it to write a pretty
comprehensive batch file, to process an openscad svg and generate a
specific version of g-code. It started off by saying it couldn't parse
a file, but it lied. It is taking a while, as I test each iteration,
but it will get there. The result will have plenty of room for
improvement, but It will work good enough.
On 25/05/2023 12:43, nop head wrote:
I use the version built into Bing, which is ChatGPT4 I believe and it
is much better.
So far, managed to generate code to batch process an scad file, doing
various sections, and combining the SVG files. It is struggling with
converting the SVG to g code.
I've patiently gone through 33 iterations of trying the batch file
script generated by the AI (within Bing), and feeding back the errors or
results. It eventually seems to get into a loop, repeating previous
guesses.
This is the input file (just one line)
M 10,-10 L 60,-10 L 60,-60 L 10,-60 z
The output that I want which should be
G01 Z-5
G01 X10 Y10
G01 X60 Y10
G01 X60 Y60
G01 X10 Y60
G00 Z2
I think the closest it has got is the following batch file
@echo off
setlocal enabledelayedexpansion
set "inputFile=input.txt"
set "outputFile=output.txt"
if exist "%outputFile%" del "%outputFile%"
for /f "usebackq delims=" %%a in ("%inputFile%") do (
set "line=%%a"
set "firstM=1"
for %%b in (!line!) do (
if "%%b" == "M" (
if "!firstM!" == "1" (
echo G01 Z-5 >> "%outputFile%"
set "firstM=0"
)
set coord=
) else if "%%b" == "L" (
echo !coord! >> "%outputFile%"
set coord=
) else if "%%b" == "z" (
echo !coord! >> "%outputFile%"
echo G00 Z2 >> "%outputFile%"
) else (
for /f "tokens=1,2 delims=," %%x in ("%%b") do (
set y=%%y
set /a y=-1*!y!
if not defined coord (
set coord=G01 X%%x Y!y!
)
)
)
)
if defined coord echo !coord! >> "%outputFile%"
)
endlocal
it does not show the Y values, although in earlier attempts it did, but
produced other errors.
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
I'll get it to try Python. It says it can. If it struggles, maybe you or
someone else can jump in. I've modified Python code, slightly, but never
done anything from scratch.
Well, it seems better on python.
I asked :-
'using Python, write the code for the following. Given an svg file
with the following line
M 10.7,-10.5 L 60,-10.5 L 60,-60 L 10.7,-60 z
generate the code to convert it to a gcode file, which should be
G01 Z-5
G01 X10.7 Y10.5
G01 X60 Y10.5
G01 X60 Y60
G01 X10.7 Y60
G00 Z2
basically, the M becomes
G01 Z-5
G01
the L becomes
G01
the z becomes
G00 Z2
the numbers stay as they are, but the one after the ',' is negated
The input file may have upper/lower case letters, and extra or fewer
spaces and many similar lines'
and after about a dozen corrections, (at least three or four of which
were me asking how to run python, it came up with
def svg_to_gcode(svg_line):
# Split the line into a list of commands and coordinates
svg_line = svg_line.strip().split()
gcode = []
for item in svg_line:
if item.upper() == 'M':
gcode.append('G01 Z-5')
# gcode.append('G01')
elif item.upper() == 'L':
if not gcode[-1].startswith('G01'):
gcode.append('G01')
elif item.upper() == 'Z':
gcode.append('G00 Z2')
else:
# Split the coordinates and negate the second one
x, y = item.split(',')
y = str(-float(y))
if not gcode[-1].startswith('G01'):
gcode.append(f'G01 X{x} Y{y}')
else:
gcode.append(f'G01 X{x} Y{y}')
return '\n'.join(gcode)
def convert_svg_file_to_gcode(input_file, output_file):
with open(input_file, 'r') as f_in, open(output_file, 'w') as f_out:
for line in f_in:
gcode = svg_to_gcode(line)
f_out.write(gcode + '\n')
convert_svg_file_to_gcode('input.txt', 'output.txt')
which I save as ' line1.py' and run with the command 'python line1.py'
and it works, but have to test more thoroughly. I'd heard others say it
was sort of OK with Python. However, it did get itself into an error
loop, wrt the G01 being on separate lines, but I managed to break it out
of that.
Now to see, if the other components, written as batch files, are easily
converted to python, and discard the 50 or soother failed versions
On 29/05/2023 12:06, nop head wrote:
I write as little as possible in batch files. Python is a much better
language and works on all platforms.
On Mon, 29 May 2023 at 12:03, Raymond West raywest@raywest.com wrote:
It is a test, as far as I'm concerned, for the capabilities of AI.
However, although it has produced a batch file that almost does
the job, it does not seem capable of going the final mile, so to
speak. When you sort of get down into the weeds, it says it
understands what it has done wrong, says that the following script
corrects the error, but then the script is a repeat of the
previous one. I'm not sure whether to push it further. It is
relatively trivial for me to write a bit of c++/whatever, to solve
this task, but trying to get the AI to do it is my current
interest. Maybe it is better at Python.
On 28/05/2023 15:07, William F. Adams wrote:
Neat that you're making progress on this!
I approached it from a rather different perspective and instead
used RapCAD for G-code generation:
https://github.com/WillAdams/gcodepreview
I've been documenting it at:
https://willadams.gitbook.io/design-into-3d/programming#gcodepreview
and have been using it inside OpenSCAD Graph Editor:
https://github.com/derkork/openscad-graph-editor
William
-----Original Message-----
From: Ray West <raywest@raywest.com> <mailto:raywest@raywest.com>
To: OpenSCAD general discussion <Discuss@lists.openscad.org>
<mailto:Discuss@lists.openscad.org>
Sent: Sun, May 28, 2023 9:09 am
Subject: [OpenSCAD] OT openai/batch file/svg parse/gcode generate
I thought there may be some interest in how it was proceeding,
following
on from a previous thread.
On 25/05/2023 19:14, Raymond West wrote:
You're dead right there, wrt Bing. I'm getting it to write a
pretty
comprehensive batch file, to process an openscad svg and
generate a
specific version of g-code. It started off by saying it
couldn't parse
a file, but it lied. It is taking a while, as I test each
iteration,
but it will get there. The result will have plenty of room for
improvement, but It will work good enough.
On 25/05/2023 12:43, nop head wrote:
I use the version built into Bing, which is ChatGPT4 I
believe and it
is much better.
So far, managed to generate code to batch process an scad file,
doing
various sections, and combining the SVG files. It is struggling with
converting the SVG to g code.
I've patiently gone through 33 iterations of trying the batch file
script generated by the AI (within Bing), and feeding back the
errors or
results. It eventually seems to get into a loop, repeating
previous guesses.
This is the input file (just one line)
M 10,-10 L 60,-10 L 60,-60 L 10,-60 z
The output that I want which should be
G01 Z-5
G01 X10 Y10
G01 X60 Y10
G01 X60 Y60
G01 X10 Y60
G00 Z2
I think the closest it has got is the following batch file
@echo off
setlocal enabledelayedexpansion
set "inputFile=input.txt"
set "outputFile=output.txt"
if exist "%outputFile%" del "%outputFile%"
for /f "usebackq delims=" %%a in ("%inputFile%") do (
set "line=%%a"
set "firstM=1"
for %%b in (!line!) do (
if "%%b" == "M" (
if "!firstM!" == "1" (
echo G01 Z-5 >> "%outputFile%"
set "firstM=0"
)
set coord=
) else if "%%b" == "L" (
echo !coord! >> "%outputFile%"
set coord=
) else if "%%b" == "z" (
echo !coord! >> "%outputFile%"
echo G00 Z2 >> "%outputFile%"
) else (
for /f "tokens=1,2 delims=," %%x in ("%%b") do (
set y=%%y
set /a y=-1*!y!
if not defined coord (
set coord=G01 X%%x Y!y!
)
)
)
)
if defined coord echo !coord! >> "%outputFile%"
)
endlocal
it does not show the Y values, although in earlier attempts it
did, but
produced other errors.
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org
Why not just publish more attempts of what you want to do, then wait a while so the AI can mine and learn from your efforts and maybe synthesise the 1% more that is required to look like an intelligent agent. It must be an ok strategy, as that is what I do, add the 1%..
Cheers, RobW
On 30 May 2023 12:58:25 am AEST, Raymond West raywest@raywest.com wrote:
I'll get it to try Python. It says it can. If it struggles, maybe you or someone else can jump in. I've modified Python code, slightly, but never done anything from scratch.
Well, it seems better on python.
I asked :-
'using Python, write the code for the following. Given an svg file with the following line
M 10.7,-10.5 L 60,-10.5 L 60,-60 L 10.7,-60 z
generate the code to convert it to a gcode file, which should be
G01 Z-5
G01 X10.7 Y10.5
G01 X60 Y10.5
G01 X60 Y60
G01 X10.7 Y60
G00 Z2
basically, the M becomes
G01 Z-5
G01
the L becomes
G01
the z becomes
G00 Z2
the numbers stay as they are, but the one after the ',' is negated
The input file may have upper/lower case letters, and extra or fewer spaces and many similar lines'
and after about a dozen corrections, (at least three or four of which were me asking how to run python, it came up with
def svg_to_gcode(svg_line):
# Split the line into a list of commands and coordinates
svg_line = svg_line.strip().split()
gcode = []
for item in svg_line:
if item.upper() == 'M':
gcode.append('G01 Z-5')
# gcode.append('G01')
elif item.upper() == 'L':
if not gcode[-1].startswith('G01'):
gcode.append('G01')
elif item.upper() == 'Z':
gcode.append('G00 Z2')
else:
# Split the coordinates and negate the second one
x, y = item.split(',')
y = str(-float(y))
if not gcode[-1].startswith('G01'):
gcode.append(f'G01 X{x} Y{y}')
else:
gcode.append(f'G01 X{x} Y{y}')
return '\n'.join(gcode)
def convert_svg_file_to_gcode(input_file, output_file):
with open(input_file, 'r') as f_in, open(output_file, 'w') as f_out:
for line in f_in:
gcode = svg_to_gcode(line)
f_out.write(gcode + '\n')
convert_svg_file_to_gcode('input.txt', 'output.txt')
which I save as ' line1.py' and run with the command 'python line1.py' and it works, but have to test more thoroughly. I'd heard others say it was sort of OK with Python. However, it did get itself into an error loop, wrt the G01 being on separate lines, but I managed to break it out of that.
Now to see, if the other components, written as batch files, are easily converted to python, and discard the 50 or soother failed versions
On 29/05/2023 12:06, nop head wrote:
I write as little as possible in batch files. Python is a much better language and works on all platforms.
On Mon, 29 May 2023 at 12:03, Raymond West raywest@raywest.com wrote:
It is a test, as far as I'm concerned, for the capabilities of AI.
However, although it has produced a batch file that almost does
the job, it does not seem capable of going the final mile, so to
speak. When you sort of get down into the weeds, it says it
understands what it has done wrong, says that the following script
corrects the error, but then the script is a repeat of the
previous one. I'm not sure whether to push it further. It is
relatively trivial for me to write a bit of c++/whatever, to solve
this task, but trying to get the AI to do it is my current
interest. Maybe it is better at Python.
On 28/05/2023 15:07, William F. Adams wrote:
Neat that you're making progress on this!
I approached it from a rather different perspective and instead
used RapCAD for G-code generation:
https://github.com/WillAdams/gcodepreview
I've been documenting it at:
https://willadams.gitbook.io/design-into-3d/programming#gcodepreview
and have been using it inside OpenSCAD Graph Editor:
https://github.com/derkork/openscad-graph-editor
William
-----Original Message-----
From: Ray West <raywest@raywest.com> <mailto:raywest@raywest.com>
To: OpenSCAD general discussion <Discuss@lists.openscad.org>
<mailto:Discuss@lists.openscad.org>
Sent: Sun, May 28, 2023 9:09 am
Subject: [OpenSCAD] OT openai/batch file/svg parse/gcode generate
I thought there may be some interest in how it was proceeding,
following
on from a previous thread.
On 25/05/2023 19:14, Raymond West wrote:
You're dead right there, wrt Bing. I'm getting it to write a
pretty
comprehensive batch file, to process an openscad svg and
generate a
specific version of g-code. It started off by saying it
couldn't parse
a file, but it lied. It is taking a while, as I test each
iteration,
but it will get there. The result will have plenty of room for
improvement, but It will work good enough.
On 25/05/2023 12:43, nop head wrote:
I use the version built into Bing, which is ChatGPT4 I
believe and it
is much better.
So far, managed to generate code to batch process an scad file,
doing
various sections, and combining the SVG files. It is struggling with
converting the SVG to g code.
I've patiently gone through 33 iterations of trying the batch file
script generated by the AI (within Bing), and feeding back the
errors or
results. It eventually seems to get into a loop, repeating
previous guesses.
This is the input file (just one line)
M 10,-10 L 60,-10 L 60,-60 L 10,-60 z
The output that I want which should be
G01 Z-5
G01 X10 Y10
G01 X60 Y10
G01 X60 Y60
G01 X10 Y60
G00 Z2
I think the closest it has got is the following batch file
@echo off
setlocal enabledelayedexpansion
set "inputFile=input.txt"
set "outputFile=output.txt"
if exist "%outputFile%" del "%outputFile%"
for /f "usebackq delims=" %%a in ("%inputFile%") do (
set "line=%%a"
set "firstM=1"
for %%b in (!line!) do (
if "%%b" == "M" (
if "!firstM!" == "1" (
echo G01 Z-5 >> "%outputFile%"
set "firstM=0"
)
set coord=
) else if "%%b" == "L" (
echo !coord! >> "%outputFile%"
set coord=
) else if "%%b" == "z" (
echo !coord! >> "%outputFile%"
echo G00 Z2 >> "%outputFile%"
) else (
for /f "tokens=1,2 delims=," %%x in ("%%b") do (
set y=%%y
set /a y=-1*!y!
if not defined coord (
set coord=G01 X%%x Y!y!
)
)
)
)
if defined coord echo !coord! >> "%outputFile%"
)
endlocal
it does not show the Y values, although in earlier attempts it
did, but
produced other errors.
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org
For those that may be interested, I've attached the final python code
that ChatGPT wrote. All I did, was ask how to do whatever, along the
lines of my previous post. I never told it to use regular expressions -
I've never used them myself, but it will explain their use. i then asked
if making a GUI was possible, and it did that, then modified it into two
columns, etc. when I asked. It is quicker to ask it to rewrite the whole
code, compared to me altering selected limes, which is prone to errors.
This was a far better experience compared to getting it to write
openscad or batch file scripts.
Thanks, Chris, for the Python suggestion. It works really well with ChatGPT.
On 29/05/2023 15:58, Raymond West wrote:
I'll get it to try Python. It says it can. If it struggles, maybe you
or someone else can jump in. I've modified Python code, slightly, but
never done anything from scratch.
Well, it seems better on python.
I asked :-
'using Python, write the code for the following. Given an svg file
with the following line
M 10.7,-10.5 L 60,-10.5 L 60,-60 L 10.7,-60 z
generate the code to convert it to a gcode file, which should be
G01 Z-5
G01 X10.7 Y10.5
G01 X60 Y10.5
G01 X60 Y60
G01 X10.7 Y60
G00 Z2
basically, the M becomes
G01 Z-5
G01
the L becomes
G01
the z becomes
G00 Z2
the numbers stay as they are, but the one after the ',' is negated
The input file may have upper/lower case letters, and extra or fewer
spaces and many similar lines'
and after about a dozen corrections, (at least three or four of which
were me asking how to run python, it came up with
def svg_to_gcode(svg_line):
# Split the line into a list of commands and coordinates
svg_line = svg_line.strip().split()
gcode = []
for item in svg_line:
if item.upper() == 'M':
gcode.append('G01 Z-5')
# gcode.append('G01')
elif item.upper() == 'L':
if not gcode[-1].startswith('G01'):
gcode.append('G01')
elif item.upper() == 'Z':
gcode.append('G00 Z2')
else:
# Split the coordinates and negate the second one
x, y = item.split(',')
y = str(-float(y))
if not gcode[-1].startswith('G01'):
gcode.append(f'G01 X{x} Y{y}')
else:
gcode.append(f'G01 X{x} Y{y}')
return '\n'.join(gcode)
def convert_svg_file_to_gcode(input_file, output_file):
with open(input_file, 'r') as f_in, open(output_file, 'w') as f_out:
for line in f_in:
gcode = svg_to_gcode(line)
f_out.write(gcode + '\n')
convert_svg_file_to_gcode('input.txt', 'output.txt')
which I save as ' line1.py' and run with the command 'python
line1.py' and it works, but have to test more thoroughly. I'd heard
others say it was sort of OK with Python. However, it did get itself
into an error loop, wrt the G01 being on separate lines, but I managed
to break it out of that.
Now to see, if the other components, written as batch files, are
easily converted to python, and discard the 50 or soother failed versions
On 29/05/2023 12:06, nop head wrote:
I write as little as possible in batch files. Python is a much better
language and works on all platforms.
On Mon, 29 May 2023 at 12:03, Raymond West raywest@raywest.com wrote:
It is a test, as far as I'm concerned, for the capabilities of
AI. However, although it has produced a batch file that almost
does the job, it does not seem capable of going the final mile,
so to speak. When you sort of get down into the weeds, it says it
understands what it has done wrong, says that the following
script corrects the error, but then the script is a repeat of the
previous one. I'm not sure whether to push it further. It is
relatively trivial for me to write a bit of c++/whatever, to
solve this task, but trying to get the AI to do it is my current
interest. Maybe it is better at Python.
On 28/05/2023 15:07, William F. Adams wrote:
Neat that you're making progress on this!
I approached it from a rather different perspective and instead
used RapCAD for G-code generation:
https://github.com/WillAdams/gcodepreview
I've been documenting it at:
https://willadams.gitbook.io/design-into-3d/programming#gcodepreview
and have been using it inside OpenSCAD Graph Editor:
https://github.com/derkork/openscad-graph-editor
William
-----Original Message-----
From: Ray West <raywest@raywest.com> <mailto:raywest@raywest.com>
To: OpenSCAD general discussion <Discuss@lists.openscad.org>
<mailto:Discuss@lists.openscad.org>
Sent: Sun, May 28, 2023 9:09 am
Subject: [OpenSCAD] OT openai/batch file/svg parse/gcode generate
I thought there may be some interest in how it was proceeding,
following
on from a previous thread.
On 25/05/2023 19:14, Raymond West wrote:
You're dead right there, wrt Bing. I'm getting it to write a
pretty
comprehensive batch file, to process an openscad svg and
generate a
specific version of g-code. It started off by saying it
couldn't parse
a file, but it lied. It is taking a while, as I test each
iteration,
but it will get there. The result will have plenty of room for
improvement, but It will work good enough.
On 25/05/2023 12:43, nop head wrote:
I use the version built into Bing, which is ChatGPT4 I
believe and it
is much better.
So far, managed to generate code to batch process an scad file,
doing
various sections, and combining the SVG files. It is struggling
with
converting the SVG to g code.
I've patiently gone through 33 iterations of trying the batch file
script generated by the AI (within Bing), and feeding back the
errors or
results. It eventually seems to get into a loop, repeating
previous guesses.
This is the input file (just one line)
M 10,-10 L 60,-10 L 60,-60 L 10,-60 z
The output that I want which should be
G01 Z-5
G01 X10 Y10
G01 X60 Y10
G01 X60 Y60
G01 X10 Y60
G00 Z2
I think the closest it has got is the following batch file
@echo off
setlocal enabledelayedexpansion
set "inputFile=input.txt"
set "outputFile=output.txt"
if exist "%outputFile%" del "%outputFile%"
for /f "usebackq delims=" %%a in ("%inputFile%") do (
set "line=%%a"
set "firstM=1"
for %%b in (!line!) do (
if "%%b" == "M" (
if "!firstM!" == "1" (
echo G01 Z-5 >> "%outputFile%"
set "firstM=0"
)
set coord=
) else if "%%b" == "L" (
echo !coord! >> "%outputFile%"
set coord=
) else if "%%b" == "z" (
echo !coord! >> "%outputFile%"
echo G00 Z2 >> "%outputFile%"
) else (
for /f "tokens=1,2 delims=," %%x in ("%%b") do (
set y=%%y
set /a y=-1*!y!
if not defined coord (
set coord=G01 X%%x Y!y!
)
)
)
)
if defined coord echo !coord! >> "%outputFile%"
)
endlocal
it does not show the Y values, although in earlier attempts it
did, but
produced other errors.
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org
Interesting way to do it. I would have parsed the input and extracted the
information with re and then printed the new format to a file, rather than
modifying it in place with re.
On Sat, 3 Jun 2023 at 11:00, Ray West raywest@raywest.com wrote:
For those that may be interested, I've attached the final python code that
ChatGPT wrote. All I did, was ask how to do whatever, along the lines of my
previous post. I never told it to use regular expressions - I've never used
them myself, but it will explain their use. i then asked if making a GUI
was possible, and it did that, then modified it into two columns, etc. when
I asked. It is quicker to ask it to rewrite the whole code, compared to me
altering selected limes, which is prone to errors.
This was a far better experience compared to getting it to write openscad
or batch file scripts.
Thanks, Chris, for the Python suggestion. It works really well with
ChatGPT.
On 29/05/2023 15:58, Raymond West wrote:
I'll get it to try Python. It says it can. If it struggles, maybe you or
someone else can jump in. I've modified Python code, slightly, but never
done anything from scratch.
Well, it seems better on python.
I asked :-
'using Python, write the code for the following. Given an svg file with
the following line
M 10.7,-10.5 L 60,-10.5 L 60,-60 L 10.7,-60 z
generate the code to convert it to a gcode file, which should be
G01 Z-5
G01 X10.7 Y10.5
G01 X60 Y10.5
G01 X60 Y60
G01 X10.7 Y60
G00 Z2
basically, the M becomes
G01 Z-5
G01
the L becomes
G01
the z becomes
G00 Z2
the numbers stay as they are, but the one after the ',' is negated
The input file may have upper/lower case letters, and extra or fewer
spaces and many similar lines'
and after about a dozen corrections, (at least three or four of which were
me asking how to run python, it came up with
def svg_to_gcode(svg_line):
# Split the line into a list of commands and coordinates
svg_line = svg_line.strip().split()
gcode = []
for item in svg_line:
if item.upper() == 'M':
gcode.append('G01 Z-5')
# gcode.append('G01')
elif item.upper() == 'L':
if not gcode[-1].startswith('G01'):
gcode.append('G01')
elif item.upper() == 'Z':
gcode.append('G00 Z2')
else:
# Split the coordinates and negate the second one
x, y = item.split(',')
y = str(-float(y))
if not gcode[-1].startswith('G01'):
gcode.append(f'G01 X{x} Y{y}')
else:
gcode.append(f'G01 X{x} Y{y}')
return '\n'.join(gcode)
def convert_svg_file_to_gcode(input_file, output_file):
with open(input_file, 'r') as f_in, open(output_file, 'w') as f_out:
for line in f_in:
gcode = svg_to_gcode(line)
f_out.write(gcode + '\n')
convert_svg_file_to_gcode('input.txt', 'output.txt')
which I save as ' line1.py' and run with the command 'python line1.py'
and it works, but have to test more thoroughly. I'd heard others say it was
sort of OK with Python. However, it did get itself into an error loop, wrt
the G01 being on separate lines, but I managed to break it out of that.
Now to see, if the other components, written as batch files, are easily
converted to python, and discard the 50 or soother failed versions
On 29/05/2023 12:06, nop head wrote:
I write as little as possible in batch files. Python is a much better
language and works on all platforms.
On Mon, 29 May 2023 at 12:03, Raymond West raywest@raywest.com wrote:
It is a test, as far as I'm concerned, for the capabilities of AI.
However, although it has produced a batch file that almost does the job, it
does not seem capable of going the final mile, so to speak. When you sort
of get down into the weeds, it says it understands what it has done wrong,
says that the following script corrects the error, but then the script is a
repeat of the previous one. I'm not sure whether to push it further. It is
relatively trivial for me to write a bit of c++/whatever, to solve this
task, but trying to get the AI to do it is my current interest. Maybe it is
better at Python.
On 28/05/2023 15:07, William F. Adams wrote:
Neat that you're making progress on this!
I approached it from a rather different perspective and instead used
RapCAD for G-code generation:
https://github.com/WillAdams/gcodepreview
I've been documenting it at:
https://willadams.gitbook.io/design-into-3d/programming#gcodepreview
and have been using it inside OpenSCAD Graph Editor:
https://github.com/derkork/openscad-graph-editor
William
-----Original Message-----
From: Ray West raywest@raywest.com raywest@raywest.com
To: OpenSCAD general discussion Discuss@lists.openscad.org
Discuss@lists.openscad.org
Sent: Sun, May 28, 2023 9:09 am
Subject: [OpenSCAD] OT openai/batch file/svg parse/gcode generate
I thought there may be some interest in how it was proceeding, following
on from a previous thread.
On 25/05/2023 19:14, Raymond West wrote:
You're dead right there, wrt Bing. I'm getting it to write a pretty
comprehensive batch file, to process an openscad svg and generate a
specific version of g-code. It started off by saying it couldn't parse
a file, but it lied. It is taking a while, as I test each iteration,
but it will get there. The result will have plenty of room for
improvement, but It will work good enough.
On 25/05/2023 12:43, nop head wrote:
I use the version built into Bing, which is ChatGPT4 I believe and it
is much better.
So far, managed to generate code to batch process an scad file, doing
various sections, and combining the SVG files. It is struggling with
converting the SVG to g code.
I've patiently gone through 33 iterations of trying the batch file
script generated by the AI (within Bing), and feeding back the errors or
results. It eventually seems to get into a loop, repeating previous
guesses.
This is the input file (just one line)
M 10,-10 L 60,-10 L 60,-60 L 10,-60 z
The output that I want which should be
G01 Z-5
G01 X10 Y10
G01 X60 Y10
G01 X60 Y60
G01 X10 Y60
G00 Z2
I think the closest it has got is the following batch file
@echo off
setlocal enabledelayedexpansion
set "inputFile=input.txt"
set "outputFile=output.txt"
if exist "%outputFile%" del "%outputFile%"
for /f "usebackq delims=" %%a in ("%inputFile%") do (
set "line=%%a"
set "firstM=1"
for %%b in (!line!) do (
if "%%b" == "M" (
if "!firstM!" == "1" (
echo G01 Z-5 >> "%outputFile%"
set "firstM=0"
)
set coord=
) else if "%%b" == "L" (
echo !coord! >> "%outputFile%"
set coord=
) else if "%%b" == "z" (
echo !coord! >> "%outputFile%"
echo G00 Z2 >> "%outputFile%"
) else (
for /f "tokens=1,2 delims=," %%x in ("%%b") do (
set y=%%y
set /a y=-1*!y!
if not defined coord (
set coord=G01 X%%x Y!y!
)
)
)
)
if defined coord echo !coord! >> "%outputFile%"
)
endlocal
it does not show the Y values, although in earlier attempts it did, but
produced other errors.
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org