CadQuery:如何修复 cq.Location() 错误: TypeError: Expected three floats, OCC gp_, or 3-tuple
问题
你正在尝试使用类似以下代码构造 cq.Location 对象
cadquery_fix.py
cq.Location(1, 2, 3)但运行时你会看到以下错误消息:
cadquery_location_error.txt
File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\cadquery\occ_impl\geom.py:1011, in Location.__init__(self, *args)
1008 else:
1009 t, ax, angle = args
1010 T.SetRotation(
-> 1011 gp_Ax1(Vector().toPnt(), Vector(ax).toDir()), angle * math.pi / 180.0
1012 )
1013 T.SetTranslationPart(Vector(t).wrapped)
1015 self.wrapped = TopLoc_Location(T)
File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\cadquery\occ_impl\geom.py:91, in Vector.__init__(self, *args)
89 fV = gp_Vec(args[0])
90 else:
---> 91 raise TypeError("Expected three floats, OCC gp_, or 3-tuple")
92 elif len(args) == 0:
93 fV = gp_Vec(0, 0, 0)
TypeError: Expected three floats, OCC gp_, or 3-tuple解决方案
不要向 cq.Location() 传递三个单独的参数 - 通过添加额外的括号传递包含三个数字的元组:
cadquery_fix.py
cq.Location((1, 2, 3))If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow