def boolean_cut(shapeToCutFrom, cuttingShape): from OCC.BRepAlgoAPI import BRepAlgoAPI_Cut cut = BRepAlgoAPI_Cut(shapeToCutFrom, cuttingShape) if not cut.BuilderCanWork(): raise AssertionError("input shapes invalid") _error = {0: '- Ok', 1: '- The Object is created but Nothing is Done', 2: '- Null source shapes is not allowed', 3: '- Check types of the arguments', 4: '- Can not allocate memory for the DSFiller', 5: '- The Builder can not work with such types of arguments', 6: '- Unknown operation is not allowed', 7: '- Can not allocate memory for the Builder', } print('error status:', _error[cut.ErrorStatus()]) cut.RefineEdges() cut.FuseEdges() shp = cut.Shape() return shp
def boolean_cut(shapeToCutFrom, cuttingShape): try: cut = BRepAlgoAPI_Cut(shapeToCutFrom, cuttingShape) print 'can work?', cut.BuilderCanWork() _error = { 0: '- Ok', 1: '- The Object is created but Nothing is Done', 2: '- Null source shapes is not allowed', 3: '- Check types of the arguments', 4: '- Can not allocate memory for the DSFiller', 5: '- The Builder can not work with such types of arguments', 6: '- Unknown operation is not allowed', 7: '- Can not allocate memory for the Builder', } print 'error status:', _error[cut.ErrorStatus()] cut.RefineEdges() cut.FuseEdges() shp = cut.Shape() cut.Destroy() return shp except: print 'FAILED TO BOOLEAN CUT' return shapeToCutFrom
def boolean_cut(shapeToCutFrom, cuttingShape, debug=False): """Boolean cut tool from PythonOCC-Utils""" try: cut = BRepAlgoAPI_Cut(shapeToCutFrom, cuttingShape) if debug: print(('can work?'), cut.BuilderCanWork()) _error = {0: '- Ok', 1: '- The Object is created but Nothing is Done', 2: '- Null source shapes is not allowed', 3: '- Check types of the arguments', 4: '- Can not allocate memory for the DSFiller', 5: '- The Builder can not work with such types of arguments', 6: '- Unknown operation is not allowed', 7: '- Can not allocate memory for the Builder', } print(('error status:'), _error[cut.ErrorStatus()]) # cut.RefineEdges() shp = cut.Shape() return shp except: print('FAILED TO BOOLEAN CUT') return shapeToCutFrom