import gCode

Hello,

how can I import a readymade GCode to simulate it.

I want to cut geographic models of buildings with a 45m radius tool to simulate lightning protection. (osm models out of BlenderGIS for example)
I need those cutted surfaces to show the protected areas. (compare those envelops with and without thunder protection items)

Pycam or Freemill can generate gcodes. But they do not export the cutted model.
Blender-Cam needs updates and how-tos..
Sounds like Freecad is the last ressort :slight_smile:

Thank you for your help.

Lukas
Esslingen

Sorry,

managed it… create a solid.. create a new path, even if empty.. open the gcode file via normal import..
not yet where i want to be, but progressing..

Lukas

I can see some path next to my solid cube.. but it still not a gcode path..or is this it? how to let it run/simulate..
copy&paste inside the path editor?
in property ‘Path’/‘Gcode’ there is a bunch of commands..
need to have a checked tool,operation,model,stock and setup?

hard to get through..

Lukas

need to remove to setup infos out of the pycam/freemill export file..
do I?
lukas

no way…

tired..
test.FCStd (3.66 KB)

You should at least upload the gcode as well. The standard 10x10x10 cube doesn’t help much.

You might be interested in PR 3600

With this, you should be able to import external gcode using the gcode_pre.py preprocessor. It will create Custom ops that behave more like regular operations. You can enable/disable them and even apply dressups. So you could import externally created gcode and then add holding tags for example.

I would appreciate some testing.

Thanks for your help..
is this pr4600 already in 0.19.21622 ?

Lukas

Pr 3600 hasn’t been merged yet. I don’t like merging my own stuff without giving other developers a chance to comment. If I don’t hear otherwise, I’ll merge it later this week

as long as something new is being introduced. On the example of an attempt to import my code, I noticed that if we use comments marked / instead of () in our code, we may get an empty trajectory instead. And I would like to see comments for /, as well as the use of conditions, loops, subroutines, processed correctly during import -




o<101> sub
G0 X[#2 * 0.00] Y[#3 * 762.50]
G1 F[#<_pm>] Z[#1]
G1 F[#<_pb>]
X[#2 * 0.00] Y[#3 * 762.50] Z[#1]
X[#2 * 0.08] Y[#3 * 1200]
o if [#4 ge 1]
G0 Z5
G0 Y[#3 * [1200 + #<_hp>]]
G1 F[#<_pm>] Z[#1]
G1 F[#<_pb>]
o endif



/X[#2 * 0.08] Y[#3 * 1143.73] Z[#1]
X[#2 * 0.00] Y[#3 * 1525.00] Z[#1]
X[#2 * 28.13] Y[#3 * 1524.90] Z[#1]
X[#2 * 45.83] Y[#3 * 1524.80] Z[#1]
X[#2 * 55.08] Y[#3 * 1524.60] Z[#1]
X[#2 * 57.58] Y[#3 * 1524.40] Z[#1]
o<101> endsub

o<101> call [-1] [1] [1] [0]

Hello,

how to import the external code?
if opening a *.gcode file, it asks for a pre-processor, but also opens a new *.fcstd file.

doing a copy paste in the custom insert of gcode , the pre-processor filter does not apply.
so that formats may not be compatible (see pycam.ngc testfile).

like
;PYCAM_TOOLPATH_SETTINGS: START
;[Bounds]
;maxz = 0.0
;maxx = 142.0
;maxy = 54.0
;minx = -12.0
;miny = -4.0
;minz = -10.0
;
;[Tool]
;torus_radius = 0.2
;speed = 1000.0
;shape = ToroidalCutter
;tool_radius = 1.0
;feedrate = 200.0
;
;[Process]
;generator = ContourFollow
;pocketing_type = none
;engrave_offset = 0.0
;milling_style = conventional
;path_direction = x
;step_down = 1.5
;postprocessor = SimpleCutter
;overlap_percent = 0
;material_allowance = 0.0
;
;PYCAM_TOOLPATH_SETTINGS: END

which I removed.

coming closer..

Lukas

OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.21769 (Git)
Build type: Release
Branch: master
Hash: 801bfe4ba5f0910e9b2885917c521ab7fd8e9020
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)
test.FCStd (685 KB)
pycamtest.ngc.txt (652 KB)

What is the state of play on this. I’m certain I imported a gcode file last year but now using either File|Open or File|Import and selecting gcode_pre, I get messy errors.

Is this a regression or am I not doing it correctly?

09:26:52  Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/~/freecad-build/Mod/Path/PathScripts/post/gcode_pre.py", line 114, in insert
    obj = PathCustom.Create("Custom")
  File "/~/freecad-build/Mod/Path/PathScripts/PathCustom.py", line 77, in Create
    proxy = ObjectCustom(obj, name)
  File "/~/freecad-build/Mod/Path/PathScripts/PathOp.py", line 193, in __init__
    job = self.setDefaultValues(obj)
  File "/~/freecad-build/Mod/Path/PathScripts/PathOp.py", line 325, in setDefaultValues
    if 1 < len(job.Operations.Group):
<class 'AttributeError'>: 'NoneType' object has no attribute 'Operations'
09:26:52  Traceback (most recent call last):

This leaves a new “Custom” object with a blue tick. When I hit recompute I get the following.

  File "<string>", line 1, in <module>
<class 'RuntimeError'>: 'NoneType' object has no attribute 'Operations'
09:27:51  PathOp.ERROR: No parent job found for operation.

OS: Fedora 31 (Thirty One) (LXDE/LXDE)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.23935 (Git)
Build type: Release
Branch: master
Hash: d5b68febbb4989b290b9af36bb2cb21d61a87a2e
Python version: 3.7.9
Qt version: 5.13.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United Kingdom (en_GB)

Yes. Looks like a regression.

https://tracker.freecadweb.org/view.php?id=4555

What is the status on this? The mantis bug seems to be close as fixed but it currently fails if I use File | Import and select gcode-pre. Here’s the trackback it produces:

23:27:15  PathScripts.post.gcode_pre gcode preprocessor loaded.
23:27:15  preprocessing...
23:27:15  done preprocessing.
23:27:18  Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/~/freecad-build22/Mod/Path/PathScripts/post/gcode_pre.py", line 115, in insert
    obj = PathCustom.Create("Custom")
  File "/~/freecad-build22/Mod/Path/PathScripts/PathCustom.py", line 80, in Create
    obj.Proxy = ObjectCustom(obj, name, parentJob)
 File "/~/freecad-build22/Mod/Path/PathScripts/PathOp.py", line 361, in __init__
    job = self.setDefaultValues(obj)
  File "/~/freecad-build22/Mod/Path/PathScripts/PathOp.py", line 571, in setDefaultValues
    if 1 < len(job.Operations.Group):
<class 'AttributeError'>: 'NoneType' object has no attribute 'Operations'
23:27:18  Traceback (most recent call last):
  File "<string>", line 1, in <module>
<class 'RuntimeError'>: 'NoneType' object has no attribute 'Operations'

Evening.
I just attempted a g-code file import (*.nc) successfully.

I started with an existing job object in place. Next I selected the Import option from the File menu. I located and selected the desired *.nc file within the Import File window and clicked the Open button. I then selected the gcode_pre option for the Processor when prompted in the Choose a processor window, and clicked OK. The code was imported into a single Custom operation.

I have imported another file that was split into two Custom operations. I am only guessing it had something to do with the contents of that specific g-code fle.

I am using a very recent build of FreeCAD. See info below. The Windows weekly-builds are behind; I think devs and project managers are focused on preparations for the upcoming 0.20 release. Are you able to bulid from source?

Have a great night.
Russell

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.28121 (Git)
Build type: Release
Branch: master
Hash: f6ef0d1095bd4beb955e8c4577b65cf8c98bf3f7
Python 3.8.6+, Qt 5.15.2, Coin 4.0.1, OCC 7.5.0
Locale: English/United States (en_US)
Installed mods: 
  * FC_SU
  * Z_MacroStartup

Snip macro screenshot-0013d4.png
Snip macro screenshot-de41d6.png

Many thanks for the explicit instructions Russ. That worked fine !

My previous attempt was using and new project file. FC prompts to create a new job via create job dlg. At this point the treeview shows a new entry “Custom”. The dlg “model” panel is empty ( logical for a new project ) and I clicked OK. At that point I get the traceback shown above.

It seems that there is an (erroneous) assumption that some existing underlying elements are present and this is not checked for and trapped. I’ve been pointing out the need to better error trapping in FreeCAD for several years but there does not even seem to any agreement that this is desirable. There seems to be some kind aversion to this generally in Python programming.

It really would be desirable if FC could check for whatever it assumes is there before relying on it and dumping a traceback which is of zero use to the user. Alternatively the error should caught at level where it occurs and a meaningful msg shown.

I did a search for “Import GCODE into FreeCAD” and most of what I saw was threads like this one showing problems. In fact I was already doing the right thing, except that it does not appear to work from and empty project.

My need here was to visualise some GCODE I created with an awk script and to check it in the simulator. That is why I used a new project instead of cluttering an existing one.

Maybe someone needs to look at why this fails with an empty project. It seems to intend to create a new job but I only see the new operation in the tree.

Some further digging:
Creating a new job with an empty Body fails silently. This is presumably what is happening with the automatic job creation, leading to further errors when it assumes erroneously that it succeeded ( and never checked ).

With a trivial object like a cylinder in the Body, the job creation process has something to work with, however this then opens the Job Edit dlg on the Setup tab. In the meantime the import process carries on without the user closing the dlg and similar traceback occurs. On closing the job edit dlg, the tree has the new job and empty Operations object. An empty Custom object exists under Body.

The pythonist paradigm of letting errors bubble up still requires they get treated somewhere, it should not lead to a traceback.

This is probably quite trivial to pin down and fix with the information supplied here. Results here were from recent master build.


Anyway, many thanks for the tips on how do this. Just knowing it works was great. That’s enabled me to achieve what I wanted to do. :wink:

OS: Fedora 34 (Thirty Four) (LXQt//usr/share/xsessions/lxqt)
Word size of FreeCAD: 64-bit
Version: 0.20.27976 (Git)
Build type: Release
Branch: master
Hash: 84f23401709f2efb95bfb59680b8746b945136be
Python 3.9.10, Qt 5.15.2, Coin 4.0.0a, OCC 7.5.0
Locale: English/United Kingdom (en_GB)
Installed mods: 
  * FreeCAD_Assembly4 0.11.10
  * FreeCAD_assembly3

Afternoon.
I looked into this issue a little and found a couple problems. Yes, there might be some poor assumptions in place, which when false, cause the import attempt to fail. As you said, I agree that a possible solution would be to insert a Job check prior to attempting the import. Doing this, we then will run into another issue, if we use the current script workflow, in that a Job cannot be created without an existing base with current scripting functions in place (at least with my mild investigation). I made a fix for the latter no-base-Job issue, but then deleted that code by rebuilding from source on top of the code without saving. :unamused:

Anyhow, please raise an issue in GitHub and link this thread. If I find time, I may tackle this bug.

Thanks digging a little further.

Cheers,
Russell

Thanks for spending time to dig the code on this.

I suspect you are correct that this cannot be automated with no body, so it needs to exit with an appropriate error msg in report window. I will try to open an issue as you suggest.

Could I also draw you attention to this one:
https://forum.freecadweb.org/viewtopic.php?f=15&t=67304&p=581583#p581583

There is some horribly archane python output if the tool is larger than the model object in 3Dsurface. Again, I think a simple error trap could provide something a lot more helpful to the user.

When the job creation dlg has no body object, there is nothing to select. When this dlg returns a null object for body , do not create phantom Custom object in tree and exit gracefully. Currently even a cancel from this dlg creates a Custom object with no parent Job or Body present.

01:43:16  PathOp.ERROR: No parent job found for operation.

Thanks for your sterling efforts in improving FC.

I know what you mean about losing mods, I’ve done that more than once myself. The best thing is to start a new local git branch before changing anything. That protects you from a master update dumping your work. I’m far from mastering the process but at least it stops you blasting everything before you realise (unless you just delete the entire tree from filemanager instead of doing git pull to update).
phantom-custom-obj2.png
phantom-custom-obj.png
empty-job-dlg.png

Evening.
Possible solution is Path: Add missing Job when needed for import G-code [Bug] #6662

Russell

Clever. Looks like the perfect solution. There’s no need that an imported gcode file should be related to an existing body.
Nice one.