Creating a 2D path job for ShapeStrings fails

Hello,

I tried to repoduce the work shown in this YouTube video:
https://www.youtube.com/watch?v=mC21T943auk

However, when I want to create a path job, I get the following error:

15:20:50  Traceback (most recent call last):
  File "/usr/lib/freecad/Mod/Path/PathScripts/PathStock.py", line 153, in onChanged
    self.execute(obj)
  File "/usr/lib/freecad/Mod/Path/PathScripts/PathStock.py", line 147, in execute
    shape = Part.makeBox(self.length, self.width, self.height, self.origin)
<class 'ValueError'>: height of box too small
15:20:50  PathJobGui.ERROR: height of box too small
15:20:50  Traceback (most recent call last):
15:20:50    File "/usr/lib/freecad/Mod/Path/PathScripts/PathJobGui.py", line 1561, in Create
    obj = PathJob.Create("Job", base, template)
15:20:50    File "/usr/lib/freecad/Mod/Path/PathScripts/PathJob.py", line 718, in Create
    obj.Proxy = ObjectJob(obj, models, templateFile)
15:20:50    File "/usr/lib/freecad/Mod/Path/PathScripts/PathJob.py", line 244, in __init__
    obj.Stock = PathStock.CreateFromTemplate(obj, json.loads(stockTemplate))
15:20:50    File "/usr/lib/freecad/Mod/Path/PathScripts/PathStock.py", line 390, in CreateFromTemplate
    return CreateFromBase(job, neg, pos, placement)
15:20:50    File "/usr/lib/freecad/Mod/Path/PathScripts/PathStock.py", line 267, in CreateFromBase
    obj.Proxy.execute(obj)
15:20:50    File "/usr/lib/freecad/Mod/Path/PathScripts/PathStock.py", line 147, in execute
    shape = Part.makeBox(self.length, self.width, self.height, self.origin)
15:20:50  ValueError: height of box too small
15:20:50

The project file is simple: it just contains a ShapeString object (as in the YT video), but I have attached it. What is wrong here?
Thanks for any help.

My FreeCAD installation:
OS: Manjaro Linux (XFCE/xfce)
Word size of FreeCAD: 64-bit
Version: 0.20.25697 (Git)
Build type: Release
Branch: master
Hash: da918350c9efbd7751bd7e48a71cd4bded571500
Python version: 3.9.6
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.0
Locale: German/Germany (de_DE)
test.FCStd (9.71 KB)

I am not sure what went wrong, and I did not watch the video, but I had no problem with creating a Job and a path.

Capture.PNG
I just selected the ShapeString, selected the Job icon, accepted all defaults, and then selected the Engrave operation. I did not try to set any parameters.

OS: Windows 7 Version 6.1 (Build 7601: SP 1)
Word size of FreeCAD: 64-bit
Version: 0.20.25645 (Git)
Build type: Release
Branch: master
Hash: 37d9757399b4c2ec30318eb88d7cd7c508246345
Python version: 3.8.6+
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.0
Locale: English/United States (en_US)

Gene

Thanks for trying to reproduce it. The error occurs when I want to create the path job.

You are using a slightly older Python version (3.8.6+) compared to mine (3.9.6), maybe the problem comes from there?

I also use a Linux version and get the error you do.

I find if you create the path job with both your job model and the ShapeString selected the tool path will be produced.
In preparation, position the ShapeString on the surface of the job. (Z offset either the job or ShapeString)
The Depths, Final Depth setting will need to be set to the desired value.
Attached modification of your file to illustrate for V-Carve and Engrave.
.
If at some stage you get the following error, you need to save your file and close out of FreeCAD completely and restart. The saved file will then work again.

Free Select
Running the Python command 'Path_Simulator' failed:
Traceback (most recent call last):
  File "/tmp/.mount_FreeCAzGNuYe/usr/Mod/Path/PathScripts/PathSimulatorGui.py", line 588, in Activated
    pathSimulation.Activate()
  File "/tmp/.mount_FreeCAzGNuYe/usr/Mod/Path/PathScripts/PathSimulatorGui.py", line 103, in Activate
    self.onJobChange()
  File "/tmp/.mount_FreeCAzGNuYe/usr/Mod/Path/PathScripts/PathSimulatorGui.py", line 459, in onJobChange
    for op in j.Operations.OutList:

Cannot access attribute 'Operations' of deleted object

.
.
OS: Ubuntu 20.04.3 LTS (ubuntu:GNOME/ubuntu)
Word size of FreeCAD: 64-bit
Version: 0.20.25645 (Git) AppImage
Build type: Release
Branch: master
Hash: 37d9757399b4c2ec30318eb88d7cd7c508246345
Python version: 3.9.7
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.5.2
Locale: English/Australia (en_AU)
test_mod.FCStd (65.9 KB)

I can confirm the issue, I see the message in Report view. It vanishes if I extend the Z of the stock by some positive value.

I am new user of FreeCAD version 0.19 on Linux Mint and just getting started with the Path toolbox and am seeing the “length of box too small” error also.
It looks like maybe a round-off error? The amount the box is too small is tiny but appears visible at both the tip of my model and the bottom.
I’m not a coder but are self.length, self.width and self.height returning values that round down for some reason? Is there a fix somewhere?

Will you test this again please? I’m unable to reproduce the issue but I’m still on Python 3.8.10

Tested and works now without issue.

OS: macOS 10.16
Word size of FreeCAD: 64-bit
Version: 0.20.27770 (Git)
Build type: Release
Python 3.9.10, Qt 5.12.9, Coin 4.0.0, OCC 7.5.3
Locale: C/Default (C)

Unless I’ve misunderstood the OP I believe I’m still seeing this on:

OS: Ubuntu 20.04.4 LTS (MATE/mate)
Word size of FreeCAD: 64-bit
Version: 0.20.27968 (Git)
Build type: Debug
Branch: master
Hash: bda12907dee4fe3f0e7dec8f7e09e098fc5036e4
Python 3.8.10, Qt 5.12.8, Coin 4.0.0, OCC 7.5.2
Locale: English/United States (en_US)

Steps to reproduce:
Set Edit->Preferences->Path->Job Preferences->Setup

  1. Set Edit->Preferences->Path->Job Preferences->Setup
  2. Stock: Enabled
  3. Extend Models Bounding Box
  4. Ext.X: 1 mm, 1 mm
  5. Ext.Y: 1 mm, 1 mm
  6. Ext.Z: 0 mm, 0 mm
  7. Placement Disabled
  8. Create a 2D shape (Draft ShapeString or Sketcher sketch) on the XY plane
  9. Path->Job
  10. Select the 2D shape as model in the “Create Job” dialog
  11. Click OK

Result:
Job is not created and Job Edit panel is not shown
Error message

...
16:24:47    File "/.../freecad-build/Mod/Path/PathScripts/PathStock.py", line 222, in execute
    shape = Part.makeBox(self.length, self.width, self.height, self.origin)
16:24:47  ValueError: height of box too small

Workaround:
The key part is the Ext.Z parameter in Edit->Preferences->Path->Job Preferences->Setup.
Setting it to != 0 so the stock gets a height > 0 solves the issue

That makes sense and, in my opinion, is how it should work. with a 2D base object and a stock of 0 height the stock object can’t control safe heights or retraction. If you’re engraving something, how high would you expect the tool to retract between segments?

I suppose we could catch the error more elegantly and just not generate a path. What should be the correct behavior?

I think this is a bug - the error is that it tries to create a Part.Box for the stock object which fails because one dimension (z) is 0.
We should handle that - or disallow creation of jobs on 2d objects entirely.

It worked on my side, because I have in preferences for Z+ and Z- an extension of 1mm.

Handling sure is the best option. I don’t think that disallowing is an option, because engraving of 2D objects works quite well if job’s Z is set appropriately.
If it cannot be fixed for now, I would prefer to document it and leave it as is.

I agree that a stock height of 0 makes little sense.
I see the problem as: The user have to figure out that they need to change their default settings. To be able to create a job based on a 2D-model.

Some options could be
Option 1:
Show the Job Edit even if the stock is invalid. Set the offending extensions to 1mm or 1". And warn the user that the extension is not their default setting.

Option 2:
Keep everything as is but show the Job Edit even if the stock is invalid. This way the user get to a state where they can setup a valid stock.

Option 3:
Replace the stack trace with a more descriptive error message.

I think I like a combination of option 2 and 3 best. It avoids the magic behaviour of option 1. But guides the user in the direction to the solution.

Good error trapping and messaging is one of the most difficult parts of any coding exercise.

However, in this case the error message is correct and concise.

ValueError: height of box too small

Of course the real problem is what to do next. Instruction for that issue is even harder to code than the error message itself. :confused:

In other words I would vote for Options 1 and 2.

Gene