【问题标题】:How to access edge dimensions in pythonocc?如何在 pythonocc 中访问边缘尺寸?
【发布时间】:2021-03-08 06:49:24
【问题描述】:

我正在尝试使用 PythonOCC 读取 IGES 或 STEP 格式的线框数据(请参阅 this link),最终用于构建 FE 梁单元模型。

在 PythonOCC 中,我实际上可以在哪里提取有关边和曲线的属性?我已经构建了这个示例,可以打印出文件中的所有顶点:

from OCC.Extend.DataExchange import read_iges_file
from OCC.Core.TopExp import (TopExp_Explorer,
                        topexp_MapShapesAndAncestors,
                        topexp_FirstVertex,
                        topexp_LastVertex)
from OCC.Core.TopAbs import *
from OCC.Core.TopoDS import TopoDS_Shape, topods
from OCC.Core.BRep import BRep_Tool, BRep_Tool_Pnt, BRep_Tool_IsGeometric, BRep_Tool_Parameter, BRep_Tool_Curve
from OCC.Core.BRepAdaptor import BRepAdaptor_Curve
from OCC.Core.GeomTools import GeomTools_CurveSet

shape = read_iges_file('tubes.iges')

topExp = TopExp_Explorer()
topExp.Init(shape, TopAbs_EDGE)

def print_vertex(va):
    print(BRep_Tool().Pnt(va).Coord(1), BRep_Tool().Pnt(va).Coord(2), BRep_Tool().Pnt(va).Coord(3))

while topExp.More():
    edge = topExp.Current()
    first, last = topexp_FirstVertex(edge), topexp_LastVertex(edge)
    curv = BRepAdaptor_Curve(edge).Curve()
    print_vertex(first)
    print_vertex(last)
    
    topExp.Next()
    print()

也就是说,我真正想知道的是曲线是直线还是弧,如果是弧,中心点和半径是多少。

【问题讨论】:

    标签: python step pythonocc


    【解决方案1】:

    我正在尝试做类似的事情。如果这可能有用,我将使用以下 sn-p 来获取曲线的类型,然后提取顶点:

        # given and Edge edge
        curv = BRepAdaptor_Curve(edge).Curve()
        a = 0.0
        b = 0.0
        [curve_handle, a, b] = OCC.BRep.BRep_Tool.Curve(edge)
        print(curve_handle.GetObject().DynamicType().GetObject().Name())
        initial_point = OCC.gp.gp_Pnt()
        final_point = OCC.gp.gp_Pnt()
        
        curve_handle.GetObject().D0(a, initial_point)
        curve_handle.GetObject().D0(b, final_point)
        
        print(f'init: ({initial_point.X()}, {initial_point.Y()}), end ({final_point.X()}, {final_point.Y()})')
    

    【讨论】:

      猜你喜欢
      • 2021-01-10
      • 1970-01-01
      • 2013-08-18
      • 2023-02-06
      • 1970-01-01
      • 2020-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多