We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fdfb6e6 commit 5a7b4d4Copy full SHA for 5a7b4d4
2 files changed
OCCUtils/boolean.py
@@ -0,0 +1,23 @@
1
+
2
+import logging
3
+from typing import Iterable
4
5
+from OCC.Core.BOPAlgo import BOPAlgo_MakerVolume
6
+from OCC.Core.TopTools import TopTools_ListOfShape
7
+from OCC.Core.TopoDS import TopoDS_Shape
8
9
+log = logging.getLogger("OCCUtils")
10
11
12
+def common_volume(shapes):
13
+ # type: (Iterable) -> TopoDS_Shape
14
+ mv = BOPAlgo_MakerVolume()
15
+ ls = TopTools_ListOfShape()
16
+ for i in shapes:
17
+ ls.Append(i)
18
+ mv.SetArguments(ls)
19
+ mv.Perform()
20
21
+ log.debug("error status: {}".format(mv.ErrorStatus()))
22
23
+ return mv.Shape()
examples/occutils_boolean.py
@@ -0,0 +1,31 @@
+from OCC.Core.gp import gp_Pln
+from OCC.Core.gp import gp_Pnt, gp_Vec
+from OCC.Display.SimpleGui import init_display
+from OCCUtils import Topo
+from OCCUtils.Construct import make_box, make_face
+from OCCUtils.Construct import vec_to_dir
+from OCCUtils.boolean import common_volume
+def test_common_volume():
+ display, start_display, add_menu, add_function_to_menu = init_display()
+ box = make_box(100, 100, 100)
+ p, v = gp_Pnt(50, 50, 50), gp_Vec(0, 0, -1)
+ pln = gp_Pln(p, vec_to_dir(v))
+ fc = make_face(pln, -1000, 1000, -1000, 1000) # limited, not infinite plane
+ display.DisplayShape(fc, transparency=0.5)
+ common_shape = common_volume([box, fc])
+ solids = Topo(common_shape).solids()
+ display.DisplayShape(next(solids), transparency=0.5)
24
+ display.DisplayColoredShape(next(solids), "BLACK")
25
26
+ display.FitAll()
27
+ start_display()
28
29
30
+if __name__ == "__main__":
31
+ test_common_volume()
0 commit comments