CadQuery: cq.Location()-Fehler beheben – TypeError: Expected three floats, OCC gp_, or 3-tuple

English Deutsch

Problem

Du versuchst, ein cq.Location-Objekt mit Code wie dem folgenden zu konstruieren

cadquery_fix.py
cq.Location(1, 2, 3)

beim Ausführen erhältst du jedoch die folgende Fehlermeldung:

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

Lösung

Übergebe nicht drei separate Parameter an cq.Location() – übergebe stattdessen ein Tupel mit drei Zahlen, indem du ein zusätzliches Klammerpaar hinzufügst:

cadquery_fix.py
cq.Location((1, 2, 3))

Check out similar posts by category: CadQuery, Python