def cut_solid_parts(array): from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Section from OCC.Core.BRepFeat import BRepFeat_SplitShape from OCC.TopTools import TopTools_ListIteratorOfListOfShape from OCC.Extend.TopologyUtils import TopologyExplorer from OCC.Core.TopoDS import TopoDS_Face #array contains several parts for i, si in enumerate(array): #for ki in si.dico: shpi = si.solid split = BRepFeat_SplitShape(shpi) for j, sj in enumerate(array): if i != j: shpj = sj.solid sect = BRepAlgoAPI_Section(shpi, shpj, False) sect.ComputePCurveOn1(True) sect.Approximation(True) sect.SetFuzzyValue(1.e-12) sect.Build() shpsect = sect.Shape() for edg in TopologyExplorer(shpsect).edges(): face = TopoDS_Face() if sect.HasAncestorFaceOn1(edg, face): split.Add(edg, face) split.Build() lst = TopTools_ListIteratorOfListOfShape(split.Modified(shpi)) while lst.More(): for face in TopologyExplorer(lst.Value()).faces(): array[i].splitsolid.append(face) lst.Next()
def split_shells_by_solid(array, solid, display): from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Section from OCC.Core.BRepFeat import BRepFeat_SplitShape from OCC.TopTools import TopTools_ListIteratorOfListOfShape from OCC.Extend.TopologyUtils import TopologyExplorer from OCC.Core.TopoDS import TopoDS_Face for i, si in enumerate(array): for ki in si.dico: print ki sfi = si.dico[ki] split = BRepFeat_SplitShape(sfi.Shape()) sect = BRepAlgoAPI_Section(solid, sfi.Shape(), False) sect.ComputePCurveOn1(True) sect.Approximation(True) sect.SetFuzzyValue(1.e-12) sect.Build() shpsect = sect.Shape() for edg in TopologyExplorer(shpsect).edges(): face = TopoDS_Face() if sect.HasAncestorFaceOn1(edg, face): split.Add(edg, face) split.Build() ais_shape = display.DisplayColoredShape(split.Shape(), color='RED') display.Context.SetTransparency(ais_shape, 0.5)