pythonocc 读取stl stp iges brep*

该代码段展示了如何利用PythonOCC库读取不同格式的三维模型文件,包括STL、STEP、IGES和BREP。通过检查文件扩展名来确定文件类型,并调用相应的读取函数。读取成功后,使用OCC的显示模块展示模型。
摘要由CSDN通过智能技术生成

pythonocc 读取stl stp iges brep

在这里插入图片描述

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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值