BRepOffsetAPI_MakeThickSolid - Some characters canтще be hollowed out

from OCC.Core.Addons import text_to_brep, Font_FontAspect_Bold, Font_FA_Regular
from OCC.Core.BRepAdaptor import BRepAdaptor_Surface
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
from OCC.Core.GeomAbs import GeomAbs_Plane
from OCC.Display.backend import load_backend
from OCC.Core.TopTools import TopTools_ListOfShape
from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_MakeThickSolid  #maketicksolidbysimple
from OCC.Display.OCCViewer import rgb_color
load_backend('qt-pyqt5')
from OCC.Core.gp import (gp_Pnt, gp_OX,gp_OY, gp_Vec, gp_Trsf, gp_DZ, gp_Ax2, gp_Ax3,
                         gp_Pnt2d, gp_Dir2d, gp_Ax2d, gp_Pln)
from OCC.Core.TopoDS import topods, TopoDS_Compound, TopoDS_Face
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakePrism, BRepPrimAPI_MakeCylinder,BRepPrimAPI_MakeBox
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeFace, BRepBuilderAPI_Transform

from OCC.Core.BRep import BRep_Tool_Surface, BRep_Builder
from OCC.Core.Geom import Geom_Plane, Geom_CylindricalSurface

from OCC.Core.ShapeFix import ShapeFix_Shape,ShapeFix_Wireframe

def  build_zi_Shapefix():
    zi_hou = 10
    zihao = 30
    txt_Str = 'U'  #不可以DEFHIJKLMNT   QUVWXYZ   ,可以:0 ,ABCIQOPRSU
    txt_Str = 'H'  # 不可以DEFHIJKLMNT   QUVWXYZ   ,可以:0 ,ABCIQOPRSU
    txt_Font = 'Arial'
    aPrismVec = gp_Vec(0, 0, zi_hou)  # Vec face
    # D_Shape_Zi = text_to_brep(txt_Str, txt_Font, Font_FA_Regular, zihao, True)  #全部失败 #复合曲线是
    D_Shape_Zi = text_to_brep(txt_Str, txt_Font, Font_FA_Regular, zihao, False)  # 部分成功    复合曲线否fisCompositeCurve (bool)
    shape= BRepPrimAPI_MakePrism(D_Shape_Zi, aPrismVec).Shape()  # 形成字符模板TopoDS_Shape
    # display.DisplayShape(shape, update=True, color=rgb_color(0.5, 0.5, 0))  # 显示图 蓝
    def face_is_plane1(face):
        # 如果是平面,则返回True
        hs = BRep_Tool_Surface(face)
        downcast_result = Geom_Plane.DownCast(hs)
        if downcast_result is None:
            return False
        else:
            return True
    def surface_plane_from_face(aFace):
        """
        Returns the geometric plane entity from a planar surface
        """
        return Geom_Plane.DownCast(BRep_Tool_Surface(aFace))

    def scoop(shape, thickness):
        faceToRemove = None
        zMax = 1
        aFaceExplorer = TopExp_Explorer(shape, TopAbs_FACE)
        while aFaceExplorer.More():
            aFace = topods.Face(aFaceExplorer.Current())
            if face_is_plane1(aFace):
                aPlane = surface_plane_from_face(aFace)
                aPnt = aPlane.Location()
                aZ = aPnt.Z()
                # aZ = aPnt.Y()
                if aZ > zMax:# aZ < zMax---他砍掉了侧面:
                    zMax = aZ
                    faceToRemove = aFace
            aFaceExplorer.Next()

        facesToRemove = TopTools_ListOfShape()
        facesToRemove.Append(faceToRemove)

        shapeFixer = ShapeFix_Shape()
        shapeFixer.Init(shape)
        shapeFixer.SetPrecision(1)  # 精度
        shapeFixer.MaxTolerance()  # 最大允许公差 Prec# 1e-4
        shapeFixer.Perform()
        shape = shapeFixer.Shape()
        # display.DisplayShape(shape, update=True)  # 显示图 蓝
        # 第一个参数是shape,第二个是要删除的面的集合,第三个是变化后的厚度,第四个是偏差
        scoopShape = BRepOffsetAPI_MakeThickSolid(shape, facesToRemove, thickness, 0.001)
        # 1 S(TopoDS_Shape &) –
        # 2 ClosingFaces(TopTools_ListOfShape &) –
        # 3 Offset(float) –
        # 4 Tol(float) –
        # 5 Mode(BRepOffset_Mode) – default
        # 6 value is BRepOffset_Skin
        # 7 Intersection(bool) – default
        # 8 value is Standard_False
        # 9 SelfInter(bool) – default
        # 10 value is Standard_False
        # 11 Join(GeomAbs_JoinType) – default
        # 12 value is GeomAbs_Arc

        # BRepBuilderAPI.BRepBuilderAPI_MakeShape_Shape
        # step_writer.SetTolerance(1e-4)
        return scoopShape

    #挖空
    shape=scoop(shape, 1).Shape()

    # shapeFixer1 = ShapeFix_Shape()
    # shapeFixer1.Init(shape)
    # shapeFixer1.SetPrecision(1e-04)  # 精度
    # shapeFixer1.MaxTolerance()  # 最大允许公差 Prec#
    # shapeFixer1.Perform()
    # shape = shapeFixer1.Shape()

    # ShapeFix_FixSmallSolid_1=ShapeFix_Solid(shape)
    # ShapeFix_FixSmallSolid_1.Init(shape)
    # ShapeFix_FixSmallSolid_1.SetPrecision(1e-04)  # 精度
    # ShapeFix_FixSmallSolid_1.MaxTolerance()  # 最大允许公差 Prec#
    # ShapeFix_FixSmallSolid_1.Perform()
    # shape = ShapeFix_FixSmallSolid_1.FixShape()

    display.DisplayShape(shape, update=True, color=rgb_color(1, 1, 0.1))  # 显示图 蓝

if __name__ == "__main__":

    from OCC.Display.SimpleGui import init_display

    display, start_display, add_menu, add_function_to_menu = init_display()
    display.display_triedron()  # 坐標顯示
    display.set_bg_gradient_color([206, 215, 222], [0, 128, 0])  # 设置背景渐变色
    add_menu('管件字挖空管理')

    add_function_to_menu('管件字挖空管理',build_zi_Shapefix)

    start_display()

 

Kirill Gavrilov's picture

Maybe you can share a couple of screenshots and point out which characters don't work for you?

And please try using "Insert Code Snippet" (switch to "Filtered HTML" editor) to make your code readable.

yan dK's picture

Dear Kirill Gavrilov .Thank you very much. I compressed the file and send zip.

yan dK's picture

Dear Kirill Gavrilov
Thankyou very much, Kirill Gavrilov
Some words can, some can't。
The file is compressed. Thanks for your help.