code produces differences in FreeCAD vs cq-editor

131 views
Skip to first unread message

Kawayanan K

unread,
Nov 8, 2020, 12:57:22 AM11/8/20
to CadQuery
Hello,

I just started playing with cq-editor, which I have been wanting to do for a while.  I have used cadquery in FreeCAD previously, and put some of my old code into cq-editor to play with the features.  Most of my probably badly written python worked in cq-editor, but I had one that ended up with a slightly messed up object.  It is a simple funnel that is meant to be 3D printed in vase/spiralize mode (so it is simple a solid object).

I am uploading a few pictures to show what the issue is, along with my code.

using cq-editor to step through the code, it looks like the error occurs during my final union.  Can anyone point out what I am messing up? (I'm trying to get better at writing the code)


funnels in cura.png
FreeCAD funnel.png
funnel.py
cq-editor funnel.png

Adam Urbanczyk

unread,
Nov 8, 2020, 11:08:55 AM11/8/20
to CadQuery
I don't think you are messing up everything, looks like a CAD kernel issue. I tried you code and the following produces correct result:

final = funnelmiddle.union(funnellower).union(funnelupper)

Kawayanan K

unread,
Nov 8, 2020, 4:32:12 PM11/8/20
to CadQuery
After getting cq-editor working normally in windows (thank again by the way), I checked the code again.  on my computer at least, the funnel produced by cq-editor still has some strangeness when running the final union.  It is however a bit different from the cq-editor funnel I got using ubuntu on Win10.  I don't get any error in any when it is run.  For the pictures, its easiest to see in cura.  The picture with two funnels is the one from FreeCAD and the one from cq-editor on ubuntu under Win10.  The second picture is form the normal Windows cq-editor.

When playing with cq-editor some more, I ran into another thing that works in FreeCAD, but produces an error in cq-editor.  Is this group a good place to post it or is there a better place?  I can work around it, I just wanted to help by reporting bugs (assuming it is a bug and not just something I didn't understand).

funnels in cura.png
cq-editor funnel-2.png

Adam Urbanczyk

unread,
Nov 9, 2020, 2:03:07 AM11/9/20
to CadQuery
Did you try changing the order of the unions as suggested above? It did solve the issue for me.

If you found a clear bug, please open an issue on GitHub. If you are not sure, maybe better post here first.

Thanks

Bruno Agostini

unread,
Nov 9, 2020, 8:47:24 AM11/9/20
to CadQuery
I have a similar issue with the code below.
I use `union(cq.Workplane('XY').newObject([CV.val(), lid.val()]))` instead of `CV = CV.union(lid)` on purpose to show the issue. When I inverse the order of the unions it's fine.
I need this kind of construction with a list when my model has a variable number of elements to union.
CAD kernel bug?

```python
import cadquery as cq
from math import cos, sin, tan, sqrt, pi

scaleM = cq.Matrix([
[ 1., 0., 0., 0.],
[0., 1., 0., 0.],
[sin(20.*pi/180), 0., 1., 0.]])

sym0 = cq.Workplane('YZ').box(139., 65., 101.)
sym0 = sym0.translate((0., 0., 55./2.))
sym1 = sym0.translate((0., 139./2., -55./2))
sym0 = sym0.cut(sym1)
sym0 = sym0.val().transformGeometry(scaleM)
sym0 = cq.Workplane('XY').newObject([sym0])

CV = cq.Workplane('XY').rect(101., 139.).rect(100., 138.).extrude(55.)
CV = CV.val().transformGeometry(scaleM)
CV = cq.Workplane('XY').newObject([CV])
CV = CV.cut(sym0)


lid = cq.Workplane('XY').box(1., 139., 60.).translate((-100./2. ,0 , 60./2.*sin(20.*pi/180)))
CV = CV.cut(lid)
co = cq.Workplane('XY').box(1., 120., 55.).translate((-100./2. ,0 , 60./2.*sin(20.*pi/180)))
lid = lid.cut(co)
lid = lid.cut(sym0)

#CV = CV.union(lid)
CV = cq.Workplane('XY').union(cq.Workplane('XY').newObject([CV.val(), lid.val()]))
```

Kawayanan K

unread,
Nov 9, 2020, 12:01:05 PM11/9/20
to CadQuery
You are correct, changing the order of the unions fixes the issue.

The other strange discrepancy I ran into is similarly fixable by just messing around with the code a little.  There is no immediacy as I just ran into this while working through a project.  I got past it and once I cleaned up and finalize it is not a problem.   It was just strange and I don't know if it is a bug or just my messy beginner code.  Here is what I ran into:

Python:

import cadquery as cq

base = (cq.Workplane("XY").circle(37).extrude(48))

hole = (cq.Workplane("XY").circle(29.5).extrude(48))

upper = (base.faces(">Z").circle(37).extrude(42, combine=False))

side = (cq.Workplane("XY").workplane(offset=90).moveTo(33,0).rect(-66,-100, centered=False).extrude(-50))

upperside = upper.union(side)

posthole = (cq.Workplane("XY").moveTo(0,-25).workplane(offset=90).rect(38,38).extrude(-35, combine=False))

final = base.union(upperside).cut(posthole).cut(hole)

show_object(final, options={"rgba":(204, 204, 204, 0.0)})

If I run this is FreeCAD, it works.  If I run it in cq-editor I get an error "Standard_NullObject: BRep_Tool:: TopoDS_Vertex hasn't gp_Pnt".  It looks like the error occurs at line 15 (final = ...).  The strange bit is that this appeared when I made a change to line 9.  I had started with a value for the moveTo of 37 (same as the base circle) and this value does not produce an error.  In fact, as long as I make the moveTo value larger then the base circle, there is no error.  If I make it smaller then the base circle, I get the error.

As I said, I've gotten long past this with cleaner code, this popped up while I was designing a part.  It just seemed strange.

Thanks for everyone's work on CadQuery.  It is by far the program I like best to design parts to print. 

Reply all
Reply to author
Forward
0 new messages