Vertex positions for Gcode template

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
robin.jonsson.4276
Posts: 23
Joined: Thu Oct 17, 2019 9:26 pm

Vertex positions for Gcode template

Post by robin.jonsson.4276 »

Hi, I’m hoping I’m not asking for to much now. I have tried PathWB it crashed for me in the older version, went to BOBCAD, SOLIDWORK, CAMWORS and Autodesk and then back to PathWB but with version 19; trying to get a CAM program to do what I want. But I’m tired of clicking around only getting 50% of the objective. So I decided to hand program G-code instead. Which worked great! Now I’m getting exactly the toolpath that I need which will save me machining time. But I’m copying and pasting the X, Y and Z coordinates from vertexes in Freecad to my G-code in a text file by hand. Clicking on each vertex, copying it from the Python Panel, pasting it in a G-code document, round off to three decimals, adding radius of the tool being used. Time consuming.

I have multiple Parts with identical named vertexes and edges (only length and angle differs).

So I want to create a template where I have my already made G-code as a Macro in Freecad and insert X, Y or Z coordinates directly from a vertex or edge with a function. Add the radius of my tools for some coordinates. And then export it as a text file.
Right now I’m just stuck reading articles without getting result. Can someone please guide me to get started? It was a couple of years since I used python and I have already wasted weeks on CAM programs that were to no use. (If not, just direct me how to get all vertex coordinates exported to a single document so I can copy from there instead.) Thankful for help.

Example:
G00 G54 X15 Z0.2
#I want to have the value of X och Y from vertex10, adding 0.2 to the Z coordinate. The rest “G00 G54 X” and “ Z” just as text. Then export it as a .txt file so that it looks like the example above.

If someone can help me with that I believe I can get the rest done

Thanks
Regards
Robin
Attachments
GcodeMacroEx.FCStd
(24.4 KiB) Downloaded 36 times
CoderMusashi
Posts: 92
Joined: Mon Nov 19, 2018 8:26 pm

Re: Vertex positions for Gcode template

Post by CoderMusashi »

Check this info out maybe you can find your way. https://forum.freecadweb.org/viewtopic.php?f=22&t=41495 and https://forum.freecadweb.org/viewtopic.php?f=36&t=41877. I looked at your model but there is no code for me to see what your trying to do. You have no toolpaths in you file so I can't even figure out what parts you are machining in what order. This seems like a pretty straight forward task no 3d contours. Could I possibly use this model in a video tutorial?
robin.jonsson.4276
Posts: 23
Joined: Thu Oct 17, 2019 9:26 pm

Re: Vertex positions for Gcode template

Post by robin.jonsson.4276 »

Hi, I made that model just to have something easier for training (the real part is more complex with 4 axis milling on a lathe and lots of weird angles). I have hand written all Gcode in a .txt file for the real model. That's why there is no toolpath in this model. Since there is some limitation to PathWB, like missing commands G70, G71, G72, g75 and such. It's easier to get exactly what i want from hand writing, that's no problem. My problem is getting the coordinates from the vertexes in a easy way. I did some searching for how I could script it but got nowhere, that's why there is no code there either.
CoderMusashi
Posts: 92
Joined: Mon Nov 19, 2018 8:26 pm

Re: Vertex positions for Gcode template

Post by CoderMusashi »

I selected a single point on this sketch and ran this code. I then selected another point and ran the code. I did all four corners of the sketch. This picture illustrates the results of running this code every time i selected a point. Is this the information you are looking for? Those G code commands are missing because they are machine specific and not standards. Most cam systems won't have them either but can be set up for those canned cycles to be generated in the post processor.
VertexSelection.png
VertexSelection.png (124.4 KiB) Viewed 1557 times

Code: Select all

#get the selected object
selobj = Gui.Selection.getSelectionEx()[0]
print(selobj.SubElementNames)
print(selobj.PickedPoints)
chrisb
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: Vertex positions for Gcode template

Post by chrisb »

If you always want to have the same initial sequence of GCodes, you can use a Job template with a certain preamble or you can even use your own post processor.

Besides, the model which you uploaded is one of the most cumbersome I have seen here: It seems to be empty! I can see the body, with sketches and features, but if I want to use it as base object in a job I cannot see it. Part->CheckGeometry - even with BOPCheck enabled - doesn't show anything; no solid, no shell, simply nothing. How did you create it?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
robin.jonsson.4276
Posts: 23
Joined: Thu Oct 17, 2019 9:26 pm

Re: Vertex positions for Gcode template

Post by robin.jonsson.4276 »

Besides, the model which you uploaded is one of the most cumbersome I have seen here: It seems to be empty! I can see the body, with sketches and features, but if I want to use it as base object in a job I cannot see it. Part->CheckGeometry - even with BOPCheck enabled - doesn't show anything; no solid, no shell, simply nothing. How did you create it?
haha that's typical. When I look at it from some angles it disappears, I have experienced that on other models also. It's made in the version that I pasted below. It was a quick draw but with correct method:
Pard DesignWB-> Create body -> create sketch -> pad -> new sketches on each Face with different symbols -> create pocket for each sketch.
The last thing I did before uploading it was opening it in V.19 and reverse some Pad and Pockets to get Face005 on Z0. That could have messed something up.

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16131 (Git)
Build type: Release
Branch: releases/FreeCAD-0-18
Hash: 3129ae4296e40ed20e7b3d460b86e6969acbe1c3
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Swedish/Sweden (sv_SE)
If you always want to have the same initial sequence of GCodes, you can use a Job template with a certain preamble or you can even use your own post processor.
Might try Job Template now when I'm in v19. Before I couldn't even open the workbench without it crashing. My own post processor would make many things easier.

OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.19093 (Git)
Build type: Release
Branch: master
Hash: 9e4710d679d44613a1ae4264b86ef9f6d12f4e5a
Python version: 3.7.3
Qt version: 5.12.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Swedish/Sweden (sv_SE)
I selected a single point on this sketch and ran this code. I then selected another point and ran the code. I did all four corners of the sketch. This picture illustrates the results of running this code every time i selected a point. Is this the information you are looking for? Those G code commands are missing because they are machine specific and not standards. Most cam systems won't have them either but can be set up for those canned cycles to be generated in the post processor.
Yes! That's the numbers that I want! When I click on a point it presents vertex in the Python console. I need to be able to assign a name to each coordinate so I can call them individually. Like: "Vertex15_X". Then I can call for that position in my Gcode.

Code: Select all

 # Gui.Selection.addSelection('testpart_V19','Clone001','Vertex15',-14.3,-0.915,-70.4833)
chrisb
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: Vertex positions for Gcode template

Post by chrisb »

chrisb wrote: Mon Dec 30, 2019 6:55 pm Besides, the model which you uploaded is one of the most cumbersome I have seen here
I found the reason: Somehow the body has lost its tip. You can reinstall it with the context menu of the last feature.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
robin.jonsson.4276
Posts: 23
Joined: Thu Oct 17, 2019 9:26 pm

Re: Vertex positions for Gcode template

Post by robin.jonsson.4276 »

chrisb wrote: Mon Dec 30, 2019 10:34 pm I found the reason: Somehow the body has lost its tip. You can reinstall it with the context menu of the last feature.
ah yes that was my fault. For updating something I click "mark to recompute" and then F5. But sometime I press "Set tip" instead, I saw someone do it in a tutorial a long time ago, I find that button the fastest sometime. Will stop doing that now
Nextjob
Posts: 8
Joined: Mon Dec 30, 2019 7:43 pm

Re: Vertex positions for Gcode template

Post by Nextjob »

Not sure if this is what you are looking for, but I have been playing around with controlling FreeCAD via python4delphi. I have a proof of concept program that is basically a Notepad style editor which receives coordinates selected in the FreeCAD window. I could provide a link to download the code / executable if you are interested. The downside is this currently only works on windows.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Vertex positions for Gcode template

Post by Kunda1 »

Nextjob wrote: Thu Jan 16, 2020 5:12 pm Not sure if this is what you are looking for, but I have been playing around with controlling FreeCAD via python4delphi. I have a proof of concept program that is basically a Notepad style editor which receives coordinates selected in the FreeCAD window. I could provide a link to download the code / executable if you are interested. The downside is this currently only works on windows.
Sounds cool, @Nextjob!. Would you consider starting a new thread discussing this along with screenshots ?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply