总目录 >> PythonOCC入门进阶到实战(目前已更新入门篇、基础篇和进阶篇)
我们在这篇文章中绘制了带有holes的面,
本篇是在读取到外部文件如brep,igs,stp后获取面的性质,寻找面中的wires的正向与逆向
- 只显示外wire
from OCC.Extend.DataExchange import read_iges_file
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_FACE, TopAbs_WIRE
from OCC.Core.TopoDS import topods
from OCC.Core.BRepAdaptor import BRepAdaptor_Surface
from OCC.Display.SimpleGui import init_display
from OCC.Core.ShapeAnalysis import shapeanalysis_OuterWire
from OCC.Display.OCCViewer import rgb_color
# 加载零件模型文件
part = read_iges_file("assets/your_file.IGS") # 替换为你的零件模型文件路径
# 初始化3D视图
display, start_display, _, _ = init_display()
# 设置颜色
highlight_color = (0.0, 0.0, 1.0) # 蓝色
# 遍历面
face_explorer = TopExp_Explorer(part, TopAbs_FACE)
while face_explorer.More():
face = topods.Face(face_explorer.Current())
#获取wire线
wires=shapeanalysis_OuterWire(face)
display.DisplayShape(wires, color=rgb_color(0,1,0))
face_explorer.Next()
# 显示3D视图
start_display()
只显示内wire
### 面的内外环线 https://blog.csdn.net/Mechanicoder/article/details/127477160
from OCC.Extend.DataExchange import read_iges_file
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_FACE, TopAbs_WIRE
from OCC.Core.TopoDS import topods
from OCC.Core.BRepAdaptor import BRepAdaptor_Surface
from OCC.Display.SimpleGui import init_display
from OCC.Core.ShapeAnalysis import shapeanalysis_OuterWire
from OCC.Display.OCCViewer import rgb_color
# 加载零件模型文件
part = read_iges_file("assets/yourfile.IGS") # 替换为你的零件模型文件路径
# 初始化3D视图
display, start_display, _, _ = init_display()
# 设置颜色
highlight_color = (0.0, 0.0, 1.0) # 蓝色
# 提取内部为空的平面的内部边界线
face_explorer = TopExp_Explorer(part, TopAbs_FACE)
while face_explorer.More():
face = topods.Face(face_explorer.Current())
# 目标:内环线
inner_wires=[]
# 获取所有线
wire_explorer = TopExp_Explorer(face, TopAbs_WIRE)
# 获取外环wire线
outer_wires = shapeanalysis_OuterWire(face)
while wire_explorer.More():
wire = topods.Wire(wire_explorer.Current())
if not wire.IsSame(outer_wires):
inner_wires.append(wire)
wire_explorer.Next()
display.DisplayShape(inner_wires, color=rgb_color(0,0,1))
face_explorer.Next()
# 显示3D视图
start_display()
参考:
1,https://www.cnblogs.com/mechanicoder/p/16878903.html Open Cascade 获取面的内外环线
2. https://www.cnblogs.com/opencascade/p/MakeFaceWithHoles.html