pythonocc 读取stl stp iges brep*

pythonocc 读取stl stp iges brep

pythonocc 读取stl stp iges brep*_第1张图片

import sys,os
from OCC.Extend.DataExchange import read_stl_file
from OCC.Display.SimpleGui import init_display
from OCC.Extend.DataExchange import read_iges_file,read_step_file,read_stl_file
from OCC.Core.TopoDS import TopoDS_Shape
from OCC.Core.BRep import BRep_Builder
from OCC.Core.BRepTools import breptools_Read,breptools_Write

**#判断文件,然后打开对应的三维文件**
def read_filename(filename):

    kuozhanm = os.path.splitext(filename)[-1]#获取扩展名
    if  kuozhanm=='.stl': #stl
        shape = read_stl_file(filename);
    elif kuozhanm=='.stp':#step
        shape = read_step_file(filename);
    elif kuozhanm=='.iges':#iges
        shape =read_iges_file(filename);
    elif kuozhanm=='.brep': #brep
        read_box = TopoDS_Shape()
        builder = BRep_Builder()
        shape = breptools_Read(read_box, filename, builder)
    else:
        print("文件格式不对,请核对")

    if not shape:
        print("Error:can't read file");
        sys.exit(0);

    return shape

filename='./pythonocc-demos-master/assets/models/famen.stl'
shapes=read_filename(filename)

display, start_display, add_menu, add_function_to_menu = init_display()
display.DisplayShape(shapes, update=True)
start_display()

你可能感兴趣的:(python)