如何在cadquery中迭代放样线?
how to iteratively loft wires in cadquery?
我可以像这样将二维形状从一个平面放样到另一个平面:
import cadquery as cq
from jupyter_cadquery.cadquery import show
result = cq.Workplane("XY").rect(1,2).workplane() \
.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0)) \
.rect(1,2).loft(combine=True)
show(result)
我想像这样重复操作几次:
import cadquery as cq
from jupyter_cadquery.cadquery import show
wp = cq.Workplane("XY").rect(1,2).workplane()
result = None
for i in range(0,5):
wp2 = wp.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0))
if result == None:
result = wp2.rect(1,2).loft(combine=True)
else:
nextpart = wp2.rect(1,2).loft(combine=True)
result = result.union(nextpart)
wp = wp2
show(result)
我有以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-54-37e88c00eca8> in <module>
9 result = wp2.rect(1,2).loft(combine=True)
10 else:
---> 11 nextpart = wp2.rect(1,2).loft(combine=True)
12 result = result.union(nextpart)
13 wp = wp2
~/anaconda3/envs/cq-jl/lib/python3.7/site-packages/cadquery/cq.py in loft(self, filled, ruled, combine)
2897 self.ctx.pendingWires = []
2898
-> 2899 r = Solid.makeLoft(wiresToLoft, ruled)
2900
2901 if combine:
~/anaconda3/envs/cq-jl/lib/python3.7/site-packages/cadquery/occ_impl/shapes.py in makeLoft(cls, listOfWire, ruled)
1594 # the True flag requests building a solid instead of a shell.
1595 if len(listOfWire) < 2:
-> 1596 raise ValueError("More than one wire is required")
1597 loft_builder = BRepOffsetAPI_ThruSections(True, ruled)
1598
ValueError: More than one wire is required
至少,如果我抑制 for
循环并保持相同的变量分解,它会起作用:
import cadquery as cq
from jupyter_cadquery.cadquery import show
wp = cq.Workplane("XY").rect(1,2).workplane()
wp2 = wp.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0))
result = wp2.rect(1,2).loft(combine=True)
wp = wp2
show(result)
我想我已经接近结果了,但我找不到我自己弄错的地方。
重点是推回 CQ 堆栈中的最后一条连线,这是一个简单的 python 赋值无法做到的事情:
wp = wp2
所以我改成了:
wp = wp.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0)).rect(1,2).workplane()
使 CQ 内核工作。
这是工作代码:
import cadquery as cq
wp = cq.Workplane("XY").rect(1,2).workplane()
result = None
for i in range(0,5):
wp2 = wp.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0)).rect(1,2).workplane()
if result == None:
result = wp2.loft(combine=True)
else:
nextpart = wp2.loft(combine=True)
result = result.union(nextpart)
wp = wp.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0)).rect(1,2).workplane()
show_object(result, options=dict(alpha=0.5,color='red'))
结果:
我可以像这样将二维形状从一个平面放样到另一个平面:
import cadquery as cq
from jupyter_cadquery.cadquery import show
result = cq.Workplane("XY").rect(1,2).workplane() \
.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0)) \
.rect(1,2).loft(combine=True)
show(result)
我想像这样重复操作几次:
import cadquery as cq
from jupyter_cadquery.cadquery import show
wp = cq.Workplane("XY").rect(1,2).workplane()
result = None
for i in range(0,5):
wp2 = wp.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0))
if result == None:
result = wp2.rect(1,2).loft(combine=True)
else:
nextpart = wp2.rect(1,2).loft(combine=True)
result = result.union(nextpart)
wp = wp2
show(result)
我有以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-54-37e88c00eca8> in <module>
9 result = wp2.rect(1,2).loft(combine=True)
10 else:
---> 11 nextpart = wp2.rect(1,2).loft(combine=True)
12 result = result.union(nextpart)
13 wp = wp2
~/anaconda3/envs/cq-jl/lib/python3.7/site-packages/cadquery/cq.py in loft(self, filled, ruled, combine)
2897 self.ctx.pendingWires = []
2898
-> 2899 r = Solid.makeLoft(wiresToLoft, ruled)
2900
2901 if combine:
~/anaconda3/envs/cq-jl/lib/python3.7/site-packages/cadquery/occ_impl/shapes.py in makeLoft(cls, listOfWire, ruled)
1594 # the True flag requests building a solid instead of a shell.
1595 if len(listOfWire) < 2:
-> 1596 raise ValueError("More than one wire is required")
1597 loft_builder = BRepOffsetAPI_ThruSections(True, ruled)
1598
ValueError: More than one wire is required
至少,如果我抑制 for
循环并保持相同的变量分解,它会起作用:
import cadquery as cq
from jupyter_cadquery.cadquery import show
wp = cq.Workplane("XY").rect(1,2).workplane()
wp2 = wp.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0))
result = wp2.rect(1,2).loft(combine=True)
wp = wp2
show(result)
我想我已经接近结果了,但我找不到我自己弄错的地方。
重点是推回 CQ 堆栈中的最后一条连线,这是一个简单的 python 赋值无法做到的事情:
wp = wp2
所以我改成了:
wp = wp.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0)).rect(1,2).workplane()
使 CQ 内核工作。
这是工作代码:
import cadquery as cq
wp = cq.Workplane("XY").rect(1,2).workplane()
result = None
for i in range(0,5):
wp2 = wp.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0)).rect(1,2).workplane()
if result == None:
result = wp2.loft(combine=True)
else:
nextpart = wp2.loft(combine=True)
result = result.union(nextpart)
wp = wp.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0)).rect(1,2).workplane()
show_object(result, options=dict(alpha=0.5,color='red'))
结果: