Error when trying to thicken face from loft on complicated spline

38 views
Skip to first unread message

Michael E

unread,
Sep 11, 2024, 8:05:26 PM9/11/24
to CadQuery
Hi there,

I'm trying to create a surface by creating a loft from a complicated 3D set of points to a point, then selecting the face a thickening it.

I'm having two issues:

1) I can't figure out how to use an actual point as the top of the loft, for now I'm using a very small spline. Is there a simple solution here?

2) The bigger issue is that when I use my actual curve instead of the sample (below in code) I get an error when I try to thicken the face: "Null TopoDS_Shape object". I can use the first two points of the actual curve but any more gets this error. Or if I take the simpler set of points and turn the 1's to 10's I get the same error. Can't figure it out.

I'm using cadquery 2.4.0 on a mac.

Thanks!!!





import cadquery as cq
import ocp_vscode as ocp

s = 1e-6
thickness = 0.05

# sample curve for testing
sample_complicated_curve = [
(1,0,0),
(1,1,1),
(0,1,0),
(-1,1,1),
(-1,0,0),
]

# first five points of the actual curve
actual_complicated_curve = [
(94.05667341, 0. , -59.60966695),
(94.05667341, 10.89318924, -59.60966695),
(94.05667341, 21.78637847, -59.60966695),
(94.05667341, 32.67956771, -59.60966695),
(94.05667341, 43.57275695, -59.60966695),
]

# I'd prefer for this to be a single point at (0,0,100) but I haven't figured that out yet
top_point = [
(s, 0, 100),
(0, s, 100),
(-s, 0, 100),

]

bottom_edge = cq.Edge.makeSpline([cq.Vector(tuple(p)) for p in sample_complicated_curve])
top_edge = cq.Edge.makeSpline([cq.Vector(tuple(p)) for p in top_point])

result = cq.Solid.makeLoft(
[cq.Wire.assembleEdges([bottom_edge]), cq.Wire.assembleEdges([top_edge])]
)

result = cq.Workplane(obj = result)
result = result.faces().val()
result = result.thicken(-thickness)

ocp.show(result)


--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[90], line 38 34 result = cq.Workplane(obj = result) 36 result = result.faces().val() ---> 38 result = result.thicken(-thickness) 41 ocp.show(result) File ~/miniconda3/envs/cadquery/lib/python3.11/site-packages/cadquery/occ_impl/shapes.py:2708, in Face.thicken(self, thickness) 2695 builder.Initialize( 2696 self.wrapped, 2697 thickness, (...) 2703 True, 2704 ) # The last True is important to make solid 2706 builder.MakeOffsetShape() -> 2708 return Solid(builder.Shape()) File ~/miniconda3/envs/cadquery/lib/python3.11/site-packages/cadquery/occ_impl/shapes.py:373, in Shape.__init__(self, obj) 372 def __init__(self, obj: TopoDS_Shape): --> 373 self.wrapped = downcast(obj) 375 self.forConstruction = False 376 # Helps identify this solid through the use of an ID File ~/miniconda3/envs/cadquery/lib/python3.11/site-packages/cadquery/occ_impl/shapes.py:347, in downcast(obj) 342 def downcast(obj: TopoDS_Shape) -> TopoDS_Shape: 343 """ 344 Downcasts a TopoDS object to suitable specialized type 345 """ --> 347 f_downcast: Any = downcast_LUT[shapetype(obj)] 348 rv = f_downcast(obj) 350 return rv File ~/miniconda3/envs/cadquery/lib/python3.11/site-packages/cadquery/occ_impl/shapes.py:337, in shapetype(obj) 334 def shapetype(obj: TopoDS_Shape) -> TopAbs_ShapeEnum: 336 if obj.IsNull(): --> 337 raise ValueError("Null TopoDS_Shape object") 339 return obj.ShapeType() ValueError: Null TopoDS_Shape object



Michael E

unread,
Sep 12, 2024, 9:47:28 AM9/12/24
to CadQuery
Actually it does work when I use all 5 points I provided. But it doesn't work for 3 or 4 points. This just seems like a bug.

More points:

actual_complicated_curve = [
(94.05667341, 0. , -59.60966695),
(94.05667341, 10.89318924, -59.60966695),
(94.05667341, 21.78637847, -59.60966695),
(94.05667341, 32.67956771, -59.60966695),
(94.05667341, 43.57275695, -59.60966695),
(94.05667341, 54.46594619, -59.60966695),
(94.05667341, 65.35913543, -59.60966695),
(94.05667341, 76.25232466, -59.60966695),
(94.05667341, 87.1455139 , -59.60966695),
(94.05667341, 98.03870314, -59.60966695),
(84.82588622, 97.97011475, -45.59693554),
(75.4538442 , 97.54097732, -34.606197 ),
(66.08131991, 96.51014947, -25.99954775),
(56.86854926, 94.73522586, -19.31253304),
(47.98195659, 92.14983787, -14.19171967),
(39.58393923, 88.74821886, -10.3571179 ),
(31.82475469, 84.57357853, -7.57899155),
(24.8360576 , 79.7084842 , -5.6633442 ),
(18.72587641, 74.26630824, -4.44280729),
(13.52467987, 69.02341242, -3.59155482),
]

Lorenz Neureuter

unread,
Sep 12, 2024, 2:25:18 PM9/12/24
to Michael E, CadQuery
Regarding 1), the methods such as `makeLoft` or `loft` do not currently support loft to vertex.
It might be possible to enhance CQ with this feature or you could add a custom function to your project using OCP directly.  Here is a quick test:

```
import cadquery as cq
from cadquery.occ_impl.shapes import *


def myloft(w, pnt):
    """quick proof of concept try - untested"""

    builder = BRepOffsetAPI_ThruSections()

    builder.Init(False, False)
    builder.AddWire(w.wrapped)
    builder.AddVertex(vertex(pnt).wrapped)

    builder.Build()
    builder.Check()

    return Shape.cast(builder.Shape())



s = 1e-6
thickness = 0.05

# sample curve for testing
sample_complicated_curve = [
    (1, 0, 0),
    (1, 1, 1),
    (0, 1, 0),
    (-1, 1, 1),
    (-1, 0, 0),
]


bottom_edge = cq.Edge.makeSpline(
    [cq.Vector(tuple(p)) for p in sample_complicated_curve]
)

shell1 = myloft(wire(bottom_edge), (0, 0, 10))
result = offset(shell1, thickness)
```


> 2) The bigger issue

> I get an error when I try to thicken the face: "Null TopoDS_Shape object"


Yes, I can reproduce the error after thicken when the loft is performed with `top_edge`.  
Perhaps try with the modified loft function.  I did not get the error in the case I tried - replacing top_edge with the point (0, 0, 100), and using the bottom edge from `actual_complicated_curve` (CQ master branch).

--
cadquery home: https://github.com/CadQuery/cadquery
post issues at https://github.com/CadQuery/cadquery/issues
run it at home at : https://github.com/CadQuery/CQ-editor
---
You received this message because you are subscribed to the Google Groups "CadQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cadquery+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cadquery/fcdf2f4e-8e01-4edc-9cc4-a45d8bb282een%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages