'Displaying CadQuery data in a QT5 window in Python
I wrote a python program using the PyQt5 libraries. This program I can make into an executable with pyinstaller. I would like to add the functionality to show a 3D cad image based on user inputs. The CadQuery package has a nice intuitive approach and I would like to use it.
From the OCC.Display.qtDisplay I take my viewer. The problem is that the viewer does not accept the workplanes generated by CadQuery. I prefer not to export to files, but directly port the results from the cad generator to the viewer. Does anyone have any suggestions or experiences?
The following (partial) code works to display an AIS shape:
import OCC.Display.qtDisplay as qtDisplay
import cadquery as cq
self.canvas = qtDisplay.qtViewer3d(self)
self.horizontalLayout.addWidget(self.canvas)
a_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()
self.ais_box = self.canvas._display.DisplayShape(a_box)[0]
self.canvas._display.FitAll()
but adding the following code (including the example bottle) does not:
self.makebottle()
self.canvas._display.DisplayShape(self.result.solids())
self.canvas._display.FitAll()
def makebottle(self):
(L,w,t) = (20.0, 6.0, 3.0)
s = cq.Workplane("XY")
# Draw half the profile of the bottle and extrude it
p = (s.center(-L/2.0, 0).vLine(w/2.0)
.threePointArc((L/2.0, w/2.0 + t),(L, w/2.0)).vLine(-w/2.0)
.mirrorX().extrude(30.0,True))
#make the neck
p = p.faces(">Z").workplane(centerOption="CenterOfMass").circle(3.0).extrude(2.0,True)
#make a shell
self.result = p.faces(">Z").shell(0.3)
Should I try to convert the workplanes? or use another package to make this work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|